ucar.unidata.io.http
Class HTTPRandomAccessFile

java.lang.Object
  extended by ucar.unidata.io.RandomAccessFile
      extended by ucar.unidata.io.http.HTTPRandomAccessFile
All Implemented Interfaces:
java.io.DataInput, java.io.DataOutput

public class HTTPRandomAccessFile
extends RandomAccessFile

Gives access to files over HTTP, using jakarta commons HttpClient library. This version uses a single instance of HttpClient, following performance guidelines at http://jakarta.apache.org/commons/httpclient/performance.html Plus other improvements.

Author:
John Caron

Field Summary
static int defaultHTTPBufferSize
           
 
Fields inherited from class ucar.unidata.io.RandomAccessFile
BIG_ENDIAN, bigEndian, buffer, bufferStart, dataEnd, dataSize, debugAccess, debugLeaks, defaultBufferSize, endOfFile, file, fileChannel, filePosition, LITTLE_ENDIAN, location, openFiles, readonly, showOpen
 
Constructor Summary
HTTPRandomAccessFile(java.lang.String url)
           
HTTPRandomAccessFile(java.lang.String url, int bufferSize)
           
 
Method Summary
 void close()
          Close the file, and release any associated system resources.
 java.io.FileDescriptor getFD()
          Returns the opaque file descriptor object associated with this file.
static org.apache.commons.httpclient.HttpClient getHttpClient()
          Get the HttpClient object - a single instance is used.
 long length()
          Get the length of the file.
protected  int read_(long pos, byte[] buff, int offset, int len)
          Read directly from file, without going through the buffer.
 long readToByteChannel(java.nio.channels.WritableByteChannel dest, long offset, long nbytes)
          Read up to nbytes bytes, at a specified offset, send to a WritableByteChannel.
static void setHttpClient(org.apache.commons.httpclient.HttpClient client)
          Set the HttpClient object - a single instance is used.
 
Methods inherited from class ucar.unidata.io.RandomAccessFile
flush, getDebugLeaks, getFilePointer, getLocation, getOpenFiles, getRandomAccessFile, isAtEndOfFile, order, read, read, read, readBoolean, readBuffer, readByte, readBytes, readBytes, readChar, readDouble, readDouble, readFloat, readFloat, readFully, readFully, readInt, readInt, readIntUnbuffered, readLine, readLong, readLong, readShort, readShort, readString, readUnsignedByte, readUnsignedShort, readUTF, searchForward, seek, setDebugAccess, setDebugLeaks, setExtendMode, setMinLength, skipBytes, toString, unread, write, write, write, writeBoolean, writeBoolean, writeByte, writeBytes, writeBytes, writeBytes, writeChar, writeChar, writeChars, writeDouble, writeDouble, writeFloat, writeFloat, writeInt, writeInt, writeLong, writeLong, writeShort, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultHTTPBufferSize

public static int defaultHTTPBufferSize
Constructor Detail

HTTPRandomAccessFile

public HTTPRandomAccessFile(java.lang.String url)
                     throws java.io.IOException
Throws:
java.io.IOException

HTTPRandomAccessFile

public HTTPRandomAccessFile(java.lang.String url,
                            int bufferSize)
                     throws java.io.IOException
Throws:
java.io.IOException
Method Detail

setHttpClient

public static void setHttpClient(org.apache.commons.httpclient.HttpClient client)
Set the HttpClient object - a single instance is used.

Parameters:
client - the HttpClient object

getHttpClient

public static org.apache.commons.httpclient.HttpClient getHttpClient()
Get the HttpClient object - a single instance is used.

Returns:
client the HttpClient object

read_

protected int read_(long pos,
                    byte[] buff,
                    int offset,
                    int len)
             throws java.io.IOException
Read directly from file, without going through the buffer. All reading goes through here or readToByteChannel;

Overrides:
read_ in class RandomAccessFile
Parameters:
pos - start here in the file
buff - put data into this buffer
offset - buffer offset
len - this number of bytes
Returns:
actual number of bytes read
Throws:
java.io.IOException - on io error

readToByteChannel

public long readToByteChannel(java.nio.channels.WritableByteChannel dest,
                              long offset,
                              long nbytes)
                       throws java.io.IOException
Description copied from class: RandomAccessFile
Read up to nbytes bytes, at a specified offset, send to a WritableByteChannel. This will block until all bytes are read. This uses the underlying file channel directly, bypassing all user buffers.

Overrides:
readToByteChannel in class RandomAccessFile
Parameters:
dest - write to this WritableByteChannel.
offset - the offset in the file where copying will start.
nbytes - the number of bytes to read.
Returns:
the actual number of bytes read, or -1 if there is no more data due to the end of the file being reached.
Throws:
java.io.IOException - if an I/O error occurs.

length

public long length()
            throws java.io.IOException
Description copied from class: RandomAccessFile
Get the length of the file. The data in the buffer (which may not have been written the disk yet) is taken into account.

Overrides:
length in class RandomAccessFile
Returns:
the length of the file in bytes.
Throws:
java.io.IOException - if an I/O error occurrs.

close

public void close()
Description copied from class: RandomAccessFile
Close the file, and release any associated system resources.

Overrides:
close in class RandomAccessFile

getFD

public java.io.FileDescriptor getFD()
Description copied from class: RandomAccessFile
Returns the opaque file descriptor object associated with this file.

Overrides:
getFD in class RandomAccessFile
Returns:
the file descriptor object associated with this file.