Secure iNet Factory

com.jscape.inet.file
Interface JRandomAccessFile


public interface JRandomAccessFile

Instances of this interface support both reading and writing to a random access file. A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor, or index into the implied array, called the file pointer; input operations read bytes starting at the file pointer and advance the file pointer past the bytes read. If the random access file is created in read/write mode, then output operations are also available; output operations write bytes starting at the file pointer and advance the file pointer past the bytes written. Output operations that write past the current end of the implied array cause the array to be extended. The file pointer can be read by the getFilePointer method and set by the seek method.

Version:
1.0
Author:
Alex Usun

Method Summary
 void close()
          Closes this random access file stream and releases any system resources associated with the stream.
 JFile getFile()
          Returns JFile instance associated with this object.
 long getFilePointer()
          Returns the current offset in this file.
 int read()
          Reads a byte of data from this file.
 int read(byte[] b)
          Reads up to b.length bytes of data from this file into an array of bytes.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this file into an array of bytes.
 void setFilePointer(long filePointer)
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this file, starting at the current file pointer.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this file.
 void write(int b)
          Writes the specified byte to this file.
 

Method Detail

close

void close()
           throws java.io.IOException
Closes this random access file stream and releases any system resources associated with the stream. A closed random access file cannot perform input or output operations and cannot be reopened.

Throws:
java.io.IOException - if an I/O error occurred

getFilePointer

long getFilePointer()
                    throws java.io.IOException
Returns the current offset in this file.

Returns:
the offset from the beginning of the file, in bytes, at which the next read or write occurs
Throws:
java.io.IOException - if an I/O error occurred

setFilePointer

void setFilePointer(long filePointer)
                    throws java.io.IOException
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.

Parameters:
filePointer - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer
Throws:
java.io.IOException - if an I/O error occurred

read

int read()
         throws java.io.IOException
Reads a byte of data from this file. The byte is returned as an integer in the range 0 to 255 (0x00-0x0ff). This method blocks if no input is yet available.

Returns:
the next byte of data, or -1 if the end of the file has been reached.
Throws:
java.io.IOException - if an I/O error occurred

read

int read(byte[] b)
         throws java.io.IOException
Reads up to b.length bytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.

Parameters:
b - the buffer into which the data is read
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of this file has been reached.
Throws:
java.io.IOException - if an I/O error occurred

read

int read(byte[] b,
         int off,
         int len)
         throws java.io.IOException
Reads up to len bytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.

Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached
Throws:
java.io.IOException - if an I/O error occurred

write

void write(int b)
           throws java.io.IOException
Writes the specified byte to this file. The write starts at the current file pointer.

Parameters:
b - the byte to be written
Throws:
java.io.IOException - if an I/O error occurred

write

void write(byte[] b)
           throws java.io.IOException
Writes b.length bytes from the specified byte array to this file, starting at the current file pointer.

Parameters:
b - the data
Throws:
java.io.IOException - if an I/O error occurred

write

void write(byte[] b,
           int off,
           int len)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this file.

Parameters:
b - the data
off - the start offset in the data
len - the number of bytes to write
Throws:
java.io.IOException - if an I/O error occurred

getFile

JFile getFile()
Returns JFile instance associated with this object.

Returns:
returns JFile instance

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2014. All Rights Reserved