Package anvil.parser

Source Code of anvil.parser.URLInputSource

/*
* $Id: URLInputSource.java,v 1.5 2002/09/16 08:05:03 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.parser;

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

/**
* class URLInputSource
*
* @author: Jani Lehtim�ki
*/
public class URLInputSource implements InputSource
{

  private URL _url = null;
  private URLConnection _connection = null;
  private InputStream _input = null;
  private long _lastModified = -1;


  public URLInputSource(URL url) throws IOException
  {
    _url = url;
    _connection = url.openConnection();
    if (_url.getProtocol().equals("file")) {
      File file = new File(_url.getFile());
      if (file.exists()) {
        _lastModified = file.lastModified();
      }
    }
  }
 
 
  public URL getURL()
  {
    return _url;
  }
 

  public long getLastModified()
  {
    if (_lastModified != -1) {
      return _lastModified;
    }
    return _connection.getLastModified();
  }
 

  public int getLength()
  {
    return _connection.getContentLength();
  }
 
 
  public InputStream getInputStream() throws IOException
  {
    _input = _connection.getInputStream();
    return _input;
  }
 
 
  public void close() throws IOException
  {
    if (_input != null) {
      _input.close();
    }
  }
 
 
 
 
}
 
TOP

Related Classes of anvil.parser.URLInputSource

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.