org.jdtaus.core.io
Interface FileOperations


public interface FileOperations

Elementary I/O operations.

Version:
$Id: FileOperations.java 1914 2007-03-01 02:20:44Z schulte2005 $
Author:
Christian Schulte

Method Summary
 long getFilePointer()
          Returns the current offset in the file.
 long getLength()
          Returns the length of the file.
 int read(byte[] buf, int off, int len)
          Reads up to bytes of data from the file into an array of bytes.
 void read(OutputStream out)
          Reads all data from the file to some .
 void setFilePointer(long pos)
          Sets the file-pointer offset, measured from the beginning of the file, at which the next read or write occurs.
 void setLength(long newLength)
          Sets the length of the file.
 void write(byte[] buf, int off, int len)
          Writes bytes from the specified byte array starting at offset to the file.
 void write(InputStream in)
          Writes all data available from some .
 

Method Detail

getFilePointer

public long getFilePointer()
                    throws IOException
Returns the current offset in the file.

Returns:
the offset from the beginning of the file, in bytes, at which the next read or write occurs.
Throws:
IOException - if getting the current offset in the file fails.

getLength

public long getLength()
               throws IOException
Returns the length of the file.

Returns:
the length measured in bytes.
Throws:
IOException - if getting the length fails.

read

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

Parameters:
buf - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Throws:
NullPointerException - if is .
IndexOutOfBoundsException - if either or is negative or is greater than the length of .
IOException - if reading fails.

read

public void read(OutputStream out)
          throws IOException
Reads all data from the file to some . The stream will not get closed after all data has been written.

Parameters:
out - an output stream to stream to.
Throws:
NullPointerException - if is .
IOException - if reading fails.

setFilePointer

public void setFilePointer(long pos)
                    throws IOException
Sets the file-pointer offset, measured from the beginning of the 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:
pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Throws:
IllegalArgumentException - if is negative.
IOException - if setting the file-pointer offset fails.

setLength

public void setLength(long newLength)
               throws IOException
Sets the length of the file.

If the present length of the file as returned by the method is greater than the argument then the file will be truncated. In this case, if the file offset as returned by the method is greater than then after this method returns the offset will be equal to .

If the present length of the file as returned by the method is smaller than the argument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.

Parameters:
newLength - The desired length of the file.
Throws:
IllegalArgumentException - if is negative.
IOException - if setting the length fails.

write

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

Parameters:
buf - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IndexOutOfBoundsException - if either or is negative or is greater than the length of .
IOException - if writing fails.

write

public void write(InputStream in)
           throws IOException
Writes all data available from some . The stream will not get closed after all data has been read.

Parameters:
in - an input stream providing the data to be written.
Throws:
NullPointerException - if is .
IOException - if writing fails.


Copyright © 2005-2007 jDTAUS. All Rights Reserved.