Class LocalDataFileHandle
- java.lang.Object
-
- ghidra.framework.store.local.LocalDataFileHandle
-
- All Implemented Interfaces:
DataFileHandle
public class LocalDataFileHandle extends java.lang.Object implements DataFileHandle
LocalDataFileHandleprovides random access to a local File.
-
-
Constructor Summary
Constructors Constructor Description LocalDataFileHandle(java.io.File file, boolean readOnly)Construct and open a local DataFileHandle.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this random access file stream and releases any system resources associated with the stream.booleanisReadOnly()Returns true if this data file handle is open read-only.longlength()Returns the length of this file.voidread(byte[] b)Readsb.lengthbytes from this file into the byte array, starting at the current file pointer.voidread(byte[] b, int off, int len)Reads exactlylenbytes from this file into the byte array, starting at the current file pointer.voidseek(long pos)Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.voidsetLength(long newLength)Sets the length of this file.intskipBytes(int n)Attempts to skip overnbytes of input discarding the skipped bytes.voidwrite(byte[] b)Writesb.lengthbytes from the specified byte array to this file, starting at the current file pointer.voidwrite(byte[] b, int off, int len)Writeslenbytes from the specified byte array starting at offsetoffto this file.voidwrite(int b)Writes the specified byte to this file.
-
-
-
Constructor Detail
-
LocalDataFileHandle
public LocalDataFileHandle(java.io.File file, boolean readOnly) throws java.io.IOExceptionConstruct and open a local DataFileHandle.- Parameters:
file- file to be openedreadOnly- if true resulting handle may only be read.- Throws:
java.io.FileNotFoundException- if file was not foundjava.io.IOException- if an IO Error occurs
-
-
Method Detail
-
read
public void read(byte[] b) throws java.io.IOExceptionDescription copied from interface:DataFileHandleReadsb.lengthbytes from this file into the byte array, starting at the current file pointer. This method reads repeatedly from the file until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown.- Specified by:
readin interfaceDataFileHandle- Parameters:
b- the buffer into which the data is read.- Throws:
java.io.EOFException- if this file reaches the end before reading all the bytes.java.io.IOException- if an I/O error occurs.
-
read
public void read(byte[] b, int off, int len) throws java.io.IOExceptionDescription copied from interface:DataFileHandleReads exactlylenbytes from this file into the byte array, starting at the current file pointer. This method reads repeatedly from the file until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown.- Specified by:
readin interfaceDataFileHandle- Parameters:
b- the buffer into which the data is read.off- the start offset of the data.len- the number of bytes to read.- Throws:
java.io.EOFException- if this file reaches the end before reading all the bytes.java.io.IOException- if an I/O error occurs.
-
skipBytes
public int skipBytes(int n) throws java.io.IOExceptionDescription copied from interface:DataFileHandleAttempts to skip overnbytes of input discarding the skipped bytes.This method may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before
nbytes have been skipped is only one possibility. This method never throws anEOFException. The actual number of bytes skipped is returned. Ifnis negative, no bytes are skipped.- Specified by:
skipBytesin interfaceDataFileHandle- Parameters:
n- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(int b) throws java.io.IOExceptionDescription copied from interface:DataFileHandleWrites the specified byte to this file. The write starts at the current file pointer.- Specified by:
writein interfaceDataFileHandle- Parameters:
b- thebyteto be written.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(byte[] b) throws java.io.IOExceptionDescription copied from interface:DataFileHandleWritesb.lengthbytes from the specified byte array to this file, starting at the current file pointer.- Specified by:
writein interfaceDataFileHandle- Parameters:
b- the data.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(byte[] b, int off, int len) throws java.io.IOExceptionDescription copied from interface:DataFileHandleWriteslenbytes from the specified byte array starting at offsetoffto this file.- Specified by:
writein interfaceDataFileHandle- 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 occurs.
-
seek
public void seek(long pos) throws java.io.IOExceptionDescription copied from interface:DataFileHandleSets 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.- Specified by:
seekin interfaceDataFileHandle- Parameters:
pos- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
java.io.IOException- ifposis less than0or if an I/O error occurs.
-
length
public long length() throws java.io.IOExceptionDescription copied from interface:DataFileHandleReturns the length of this file.- Specified by:
lengthin interfaceDataFileHandle- Returns:
- the length of this file, measured in bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
setLength
public void setLength(long newLength) throws java.io.IOExceptionDescription copied from interface:DataFileHandleSets the length of this file.If the present length of the file as returned by the
lengthmethod is greater than thenewLengthargument then the file will be truncated. In this case, if the file offset as returned by thegetFilePointermethod is greater thennewLengththen after this method returns the offset will be equal tonewLength.If the present length of the file as returned by the
lengthmethod is smaller than thenewLengthargument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.- Specified by:
setLengthin interfaceDataFileHandle- Parameters:
newLength- The desired length of the file- Throws:
java.io.IOException- If an I/O error occurs
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:DataFileHandleCloses 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.- Specified by:
closein interfaceDataFileHandle- Throws:
java.io.IOException- if an I/O error occurs.
-
isReadOnly
public boolean isReadOnly() throws java.io.IOExceptionDescription copied from interface:DataFileHandleReturns true if this data file handle is open read-only.- Specified by:
isReadOnlyin interfaceDataFileHandle- Throws:
java.io.IOException- if an I/O error occurs.
-
-