public final class MemoryFileOperations extends Object implements org.jdtaus.core.io.FileOperations, Serializable, Cloneable
This implementation performs I/O in memory. The value of property
length
is limited to a maximum of Integer.MAX_VALUE
(4 GB).
Constructor and Description |
---|
MemoryFileOperations()
Creates a new
MemoryFileOperations instance of no length. |
MemoryFileOperations(byte[] buf)
Creates a new
MemoryFileOperations instance holding buf . |
MemoryFileOperations(int initialCapacity)
Creates a new
MemoryFileOperations instance of no length
taking an initial capacity. |
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Creates and returns a deep copy of this object.
|
void |
close()
Since this implementation does not use any system resources to
release, this method does nothing.
|
void |
ensureCapacity(int minimumCapacity)
Increases the capacity of the instance, if necessary, to ensure that it
can hold at least the number of bytes specified by the minimum capacity
argument.
|
boolean |
equals(Object o)
Indicates whether some other object is equal to this one by comparing
the contents from memory.
|
int |
getCapacity()
Gets the capacity of the instance.
|
byte[] |
getData()
Gets the file contents.
|
long |
getFilePointer() |
long |
getLength() |
int |
hashCode()
Returns a hash code value for this object.
|
int |
read(byte[] buf,
int off,
int len) |
void |
read(OutputStream out) |
void |
setFilePointer(long pos) |
void |
setLength(long newLength) |
void |
write(byte[] buf,
int off,
int len) |
void |
write(InputStream in) |
public MemoryFileOperations()
MemoryFileOperations
instance of no length.public MemoryFileOperations(int initialCapacity)
MemoryFileOperations
instance of no length
taking an initial capacity.initialCapacity
- the number of bytes to pre-allocate when
creating the new instance.OutOfMemoryError
- if not enough memory is available to create a
buffer with a length of initialCapacity
.ensureCapacity(int)
public MemoryFileOperations(byte[] buf)
MemoryFileOperations
instance holding buf
.buf
- bytes to initialize the instance with.NullPointerException
- if buf
is null
.public long getLength()
getLength
in interface org.jdtaus.core.io.FileOperations
public void setLength(long newLength)
setLength
in interface org.jdtaus.core.io.FileOperations
IllegalArgumentException
- if newLength
is negative or
greater than Integer.MAX_VALUE
.public long getFilePointer()
getFilePointer
in interface org.jdtaus.core.io.FileOperations
public void setFilePointer(long pos)
setFilePointer
in interface org.jdtaus.core.io.FileOperations
public int read(byte[] buf, int off, int len)
read
in interface org.jdtaus.core.io.FileOperations
public void write(byte[] buf, int off, int len)
write
in interface org.jdtaus.core.io.FileOperations
public void read(OutputStream out) throws IOException
read
in interface org.jdtaus.core.io.FileOperations
IOException
public void write(InputStream in) throws IOException
write
in interface org.jdtaus.core.io.FileOperations
IOException
public void close()
Since this implementation does not use any system resources to
release, this method does nothing. In contrast to other
FileOperations
implementations the instance can still be used
after calling this method. It would be a mistake to write an application
which relies on this behaviour, however.
close
in interface org.jdtaus.core.io.FileOperations
public int getCapacity()
public void ensureCapacity(int minimumCapacity)
minimumCapacity
- the minimum capacity to ensure.public byte[] getData()
OutOfMemoryError
- if not enough memory is available.public boolean equals(Object o)
public int hashCode()
Copyright © 2005-2012 jDTAUS. All Rights Reserved.