Package anvil.server

Source Code of anvil.server.URLLoader

/*
* $Id: URLLoader.java,v 1.4 2002/09/16 08:05:06 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.server;

import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;

/**
* class URLLoader
*
* @author: Jani Lehtim�ki
*/
public class URLLoader implements Loader
{

  private URL _url;

  public URLLoader(URL url)
  {
    _url = url;
  }

  public ClassData load(String name)
  {
    URL url;
    try {
      url = new URL(_url, name + ".class");
    } catch (MalformedURLException e) {
      return null;
    }
    InputStream input = null;
    try {
      input = url.openStream();
      int length = (int)input.available();
      int offset = 0;
      byte[] data = new byte[length];
      while(offset < length) {
        int read = input.read(data, offset, length - offset);
        if (read == -1) {
          return null;
        }
        offset += read;
      }
      input.close();
      return new ClassData(name, data);
    } catch (IOException e) {
      return null;
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (IOException e) {
        }
      }
    }
  }

}
TOP

Related Classes of anvil.server.URLLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.