Package anvil.util

Source Code of anvil.util.FileURLConnection

/*
* $Id: FileURLConnection.java,v 1.2 2002/09/16 08:05:07 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.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.UnknownServiceException;
import java.net.URL;
import java.net.URLConnection;

/**
* class FileURLConnection
*
* @author: Jani Lehtim�ki
*/
public class FileURLConnection extends URLConnection
{
  private String _fileName;
  private File _file;
  private long _lastModified = 0;
  private boolean _fileExists = false;


  FileURLConnection(URL url)
  {
    super(url);
    _fileName = url.getFile();
    _file = new File(_fileName);
    _fileExists = _file.exists();
    if (_fileExists) {
      _lastModified = _file.lastModified();
    }
  }

 
  public void connect() throws IOException
  {
    if (connected == false) {
      connected = true;
    }
  }


  public long getLastModified()
  {
    return _lastModified;
  }


  public boolean hasBeenModified()
  {
    return (ifModifiedSince==0) || (_lastModified > ifModifiedSince);
  }

  public InputStream getInputStream() throws IOException
  {
    connect();
    if (_fileExists) {
      return new FileInputStream(_fileName);
    } else {
      throw new IOException("File not found: "+_fileName);
    }
  }
 
 
  public OutputStream getOutputStream() throws IOException
  {
    connect();
    throw new UnknownServiceException();
  }
 
 
}

TOP

Related Classes of anvil.util.FileURLConnection

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.