TrueZIP Kernel 7.0-rc2

de.schlichtherle.truezip.rof
Class ByteArrayReadOnlyFile

java.lang.Object
  extended by de.schlichtherle.truezip.rof.AbstractReadOnlyFile
      extended by de.schlichtherle.truezip.rof.ByteArrayReadOnlyFile
All Implemented Interfaces:
ReadOnlyFile, Closeable

@ThreadSafe
@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public final class ByteArrayReadOnlyFile
extends AbstractReadOnlyFile

A read only file which reads from a byte array provided to its constructor.

Author:
Christian Schlichtherle

Field Summary
private  byte[] data
           
private  int length
           
private  int offset
           
 
Constructor Summary
ByteArrayReadOnlyFile(byte[] data)
          Constructs a new byte array read only file.
ByteArrayReadOnlyFile(byte[] data, int offset, int length)
          Constructs a new byte array read only file.
 
Method Summary
 void close()
          Closes this read-only file and releases any non-heap resources allocated for it.
 long getFilePointer()
          Returns the current byte position in the file as a zero-based index.
 long length()
          Returns the length of the file in bytes.
 int read()
          Reads and returns the next byte or -1 if the end of the file has been reached.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this read only file into the given array.
 void seek(long pos)
          Sets the current byte position in the file as a zero-based index at which the next read occurs.
 
Methods inherited from class de.schlichtherle.truezip.rof.AbstractReadOnlyFile
read, readFully, readFully
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

private final byte[] data

offset

private int offset

length

private int length
Constructor Detail

ByteArrayReadOnlyFile

public ByteArrayReadOnlyFile(byte[] data)
Constructs a new byte array read only file.

Parameters:
data - the array to read from. Note that this array is not copied, so beware of concurrent modifications!

ByteArrayReadOnlyFile

public ByteArrayReadOnlyFile(byte[] data,
                             int offset,
                             int length)
Constructs a new byte array read only file.

Parameters:
data - the array to read from. Note that this array is not copied, so beware of concurrent modifications!
offset - the start of the window to read from the array.
length - the length of the window to read from the array.
Method Detail

length

public long length()
Description copied from interface: ReadOnlyFile
Returns the length of the file in bytes.


getFilePointer

public long getFilePointer()
Description copied from interface: ReadOnlyFile
Returns the current byte position in the file as a zero-based index.


seek

public void seek(long pos)
          throws IOException
Description copied from interface: ReadOnlyFile
Sets the current byte position in the file as a zero-based index at which the next read occurs. Whether the offset may be set beyond the end of the file is up to the implementor. For example, the DefaultReadOnlyFile subclass RandomAccessFile passes "r" as a parameter to the superclass constructor. With Sun's JSE implementation, on the Windows platform this implementation allows to seek past the end of file, but on the Linux platform it doesn't.

Parameters:
pos - The current byte position as a zero-based index.
Throws:
IOException - If pos is less than 0 or if an I/O error occurs.

read

public int read()
Description copied from interface: ReadOnlyFile
Reads and returns the next byte or -1 if the end of the file has been reached.


read

public int read(byte[] b,
                int off,
                int len)
Description copied from interface: ReadOnlyFile
Reads up to len bytes of data from this read only file into the given array. This method blocks until at least one byte of input is available.

Parameters:
b - The buffer to fill with data.
off - The start offset of the data.
len - The maximum number of bytes to read.
Returns:
The total number of bytes read, or -1 if there is no more data because the end of the file has been reached.

close

public void close()
Description copied from interface: ReadOnlyFile
Closes this read-only file and releases any non-heap resources allocated for it.


TrueZIP Kernel 7.0-rc2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.