com.upokecenter.util.DataIO
com.upokecenter.util.DataIO
public final class DataIO extends Object
Convenience class that contains static methods for wrapping byte arrays and streams into byte readers and byte writers.
Methods
static IByteReader ToByteReader(byte[] bytes)
Deprecated. Use ToReader instead.static IByteReader ToByteReader(byte[] bytes, int offset, int length)
Deprecated. Use ToReader instead.static IByteReader ToByteReader(InputStream input)
Deprecated. Use ToReader instead.static IReader ToReader(byte[] bytes)
Wraps a byte array into a byte reader.static IReader ToReader(byte[] bytes, int offset, int length)
Wraps a portion of a byte array into a byte reader object.static IReader ToReader(InputStream input)
Wraps an input stream into a reader object.static IWriter ToWriter(IByteWriter output)
Wraps a byte writer (one that only implements a ReadByte method) to a writer (one that also implements a three-parameter Read method.)static IWriter ToWriter(OutputStream output)
Wraps an output stream into a writer object.
Method Details
ToReader
public static IReader ToReader(byte[] bytes)
Wraps a byte array into a byte reader. The reader will start at the beginning of the byte array.
In the.NET implementation, this method
is implemented as an extension method to any byte array object and can be
called as follows: bytes.ToByteReader()
. If the object's class
already has a ToByteReader method with the same parameters, that method
takes precedence over this extension method.
Parameters:
bytes
- The byte array to wrap.
Returns:
- A byte reader wrapping the byte array.
Throws:
NullPointerException
- The parameterbytes
is null.
ToReader
public static IReader ToReader(byte[] bytes, int offset, int length)
Wraps a portion of a byte array into a byte reader object.
In
the.NET implementation, this method is implemented as an extension method to
any byte array object and can be called as follows:
bytes.ToByteReader(offset, length)
. If the object's class already has a
ToByteReader method with the same parameters, that method takes precedence
over this extension method.
Parameters:
bytes
- The byte array to wrap.offset
- An index starting at 0 showing where the desired portion of "bytes" begins.length
- The length, in bytes, of the desired portion of "bytes" (but not more than "bytes" 's length).
Returns:
- A byte reader wrapping the byte array.
Throws:
NullPointerException
- The parameterbytes
is null.IllegalArgumentException
- Eitheroffset
orlength
is less than 0 or greater thanbytes
's length, orbytes
's length minusoffset
is less thanlength
.NullPointerException
- The parameterbytes
is null.
ToReader
public static IReader ToReader(InputStream input)
Wraps an input stream into a reader object. If an IOException is thrown by the input stream, the reader object throws IllegalStateException instead.
In the.NET implementation, this method is implemented as an
extension method to any object implementing InputStream and can be called as
follows: input.ToByteReader()
. If the object's class already has a
ToByteReader method with the same parameters, that method takes precedence
over this extension method.
Parameters:
input
- The input stream to wrap.
Returns:
- A byte reader wrapping the input stream.
Throws:
NullPointerException
- The parameterinput
is null.
ToByteReader
@Deprecated public static IByteReader ToByteReader(byte[] bytes, int offset, int length)
Wraps a portion of a byte array into a byte reader.
In the.NET
implementation, this method is implemented as an extension method to any
object implementing byte[] and can be called as follows:
bytes.ToByteReader(offset, length)
. If the object's class already has a
ToByteReader method with the same parameters, that method takes precedence
over this extension method.
Parameters:
bytes
- The byte array to wrap into a byte reader.offset
- An index starting at 0 showing where the desired portion ofbytes
begins.length
- The length, in bytes, of the desired portion ofbytes
(but not more thanbytes
's length).
Returns:
- An IByteReader object.
Throws:
NullPointerException
- The parameterbytes
is null.IllegalArgumentException
- Eitheroffset
orlength
is less than 0 or greater thanbytes
's length, orbytes
's length minusoffset
is less thanlength
.NullPointerException
- The parameterbytes
is null.
ToByteReader
@Deprecated public static IByteReader ToByteReader(InputStream input)
Wraps a data stream into a byte reader.
In the.NET
implementation, this method is implemented as an extension method to any
object implementing InputStream and can be called as follows:
input.ToByteReader()
. If the object's class already has a ToByteReader
method with the same parameters, that method takes precedence over this
extension method.
Parameters:
input
- The data stream to wrap into a byte reader.
Returns:
- An IByteReader object.
Throws:
NullPointerException
- The parameterinput
is null.
ToByteReader
@Deprecated public static IByteReader ToByteReader(byte[] bytes)
Wraps a byte array into a byte reader.
In the.NET implementation,
this method is implemented as an extension method to any object implementing
byte[] and can be called as follows: bytes.ToByteReader()
. If the
object's class already has a ToByteReader method with the same parameters,
that method takes precedence over this extension method.
Parameters:
bytes
- The byte array to wrap into a byte reader.
Returns:
- An IByteReader object.
Throws:
NullPointerException
- The parameterbytes
is null.
ToWriter
public static IWriter ToWriter(OutputStream output)
Wraps an output stream into a writer object. If an IOException is thrown by the input stream, the writer object throws IllegalStateException instead.
In the.NET implementation, this method is implemented as an
extension method to any object implementing InputStream and can be called as
follows: output.ToWriter()
. If the object's class already has a
ToWriter method with the same parameters, that method takes precedence over
this extension method.
Parameters:
output
- Output stream to wrap.
Returns:
- A byte writer that wraps the given output stream.
Throws:
NullPointerException
- The parameteroutput
is null.
ToWriter
public static IWriter ToWriter(IByteWriter output)
Wraps a byte writer (one that only implements a ReadByte method) to a writer (one that also implements a three-parameter Read method.)
In
the.NET implementation, this method is implemented as an extension method to
any object implementing IByteWriter and can be called as follows:
output.ToWriter()
. If the object's class already has a ToWriter method with
the same parameters, that method takes precedence over this extension
method.
Parameters:
output
- A byte stream.
Returns:
- A writer that wraps the given stream.
Throws:
NullPointerException
- The parameteroutput
is null.