jwadlib
Class WadByteBuffer

java.lang.Object
  extended by jwadlib.WadByteBuffer

public class WadByteBuffer
extends java.lang.Object

A wrapper class for the ByteBuffer class that specifically is designed to work with WAD file data. All data is read in little endian mode.

Since:
1.0
Version:
1.0 Alpha 1
Author:
Samuel "insertwackynamehere" Horwitz

Field Summary
private  java.nio.ByteBuffer bytebuffer
          The ByteBuffer that backs the WadByteBuffer.
private  int length
          The number of bytes this WadByteBuffer contains in it's ByteBuffer.
 
Constructor Summary
WadByteBuffer(byte[] bytearray)
          Creates a WadByteBuffer from an array of bytes.
WadByteBuffer(java.nio.channels.FileChannel bufferchannel)
          Creates a WadByteBuffer from a FileChannel from the beginning to the end of the channel.
WadByteBuffer(java.nio.channels.FileChannel bufferchannel, int bufferlength)
          Creates a WadByteBuffer from a FileChannel from the beginning of the channel until the number of specified bytes are read.
WadByteBuffer(java.nio.channels.FileChannel bufferchannel, int bufferlength, int position)
          Creates a WadByteBuffer from a FileChannel from the indicated position until the number of specified bytes are read.
WadByteBuffer(int buffersize)
          Creates an empty WadByteBuffer of a set size.
WadByteBuffer(WadByteBuffer bytebuffer)
          Creates a WadByteBuffer from another WadByteBuffer.
 
Method Summary
 boolean alterBufferSize(int newsize)
          Changes the size of the WadByteBuffer's backing ByteBuffer.
static java.lang.String convertToEightByteString(java.lang.String string)
          Converts a String to a new eight byte String by padding Strings less than eight characters and truncating Strings greater than eight characters.
private  byte[] getArray()
          Returns an array of bytes containing the contents of the ByteBuffer.
 byte getByte()
          A wrapper class for ByteBuffer's get() method; gets the next byte in the WadByteBuffer.
 byte getByte(int index)
          A wrapper class for ByteBuffer's get(int) method; gets the next byte in the WadByteBuffer, starting at the specified position.
 java.nio.ByteBuffer getByteBuffer()
          Returns the backing ByteBuffer of the WadByteBuffer.
 WadByteBuffer getByteBuffer(int offset, int length)
          Gets a sub-WadByteBuffer out of the current one, by getting a specified number of bytes starting at a specified position in the buffer.
 int getCapacity()
          Returns the capacity of the ByteBuffer.
 java.lang.String getEightByteString()
          Gets the next eight bytes in the WadByteBuffer as a String.
 java.lang.String getEightByteString(int index)
          Gets the next eight bytes in the WadByteBuffer as a String, starting at the specified position.
 int getInt()
          A wrapper class for ByteBuffer's getInt() method; gets the next integer in the WadByteBuffer.
 int getInt(int index)
          A wrapper class for ByteBuffer's getInt(int) method; gets the next integer in the WadByteBuffer, starting at the specified position.
 int getLength()
          Returns the length of the WadByteBuffer.
 int getPosition()
          A wrapper class for ByteBuffer's position() method; returns the WadByteBuffer's position.
 short getShort()
          A wrapper class for ByteBuffer's getShort() method; gets the next short in the WadByteBuffer.
 short getShort(int index)
          A wrapper class for ByteBuffer's getShort(int) method; gets the next short in the WadByteBuffer, starting at the specified position.
 boolean hasRemaining()
          A wrapper class for ByteBuffer's hasRemaining() method; returns true if the WadByteBuffer has any values left past the current position.
 WadByteBuffer put(byte b)
          A wrapper class for ByteBuffer's put(byte) method; puts a single byte into the WadByteBuffer.
 WadByteBuffer put(int index, byte b)
          A wrapper class for ByteBuffer's put(int, byte) method; puts a single byte into the WadByteBuffer at the specified position.
 WadByteBuffer put(WadByteBuffer src)
          A wrapper class for ByteBuffer's put(ByteBuffer) method; puts a ByteBuffer into the WadByteBuffer.
 WadByteBuffer putEightByteString(char[] value)
          Puts eight bytes in the WadByteBuffer as an array of characters.
 WadByteBuffer putEightByteString(int index, char[] value)
          Puts eight bytes in the WadByteBuffer as an array of characters, at the specified position.
 WadByteBuffer putEightByteString(int index, java.lang.String value)
          Puts eight bytes in the WadByteBuffer as a String at the specified position.
 WadByteBuffer putEightByteString(java.lang.String value)
          Puts eight bytes in the WadByteBuffer as a String.
 WadByteBuffer putInt(int value)
          A wrapper class for ByteBuffer's putInt(int) method; puts an integer into the WadByteBuffer.
 WadByteBuffer putInt(int index, int value)
          A wrapper class for ByteBuffer's putInt(int) method; puts an integer into the WadByteBuffer.
 WadByteBuffer putShort(int index, short value)
          A wrapper class for ByteBuffer's putShort(short) method; puts a short into the WadByteBuffer.
 WadByteBuffer putShort(short value)
          A wrapper class for ByteBuffer's putShort(short) method; puts a short into the WadByteBuffer.
 WadByteBuffer setPosition(int index)
          A wrapper class for ByteBuffer's position(int) method; sets the WadByteBuffer's position to the specified integer and returns the WadByteBuffer object that called it.
 boolean writeToFile(java.nio.channels.FileChannel filechannel)
          Writes this WadByteBuffer's data to the specified channel.
 boolean writeToFile(java.nio.channels.FileChannel filechannel, long position)
          Writes this WadByteBuffer's data to the specified channel, at the specified position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bytebuffer

private java.nio.ByteBuffer bytebuffer
The ByteBuffer that backs the WadByteBuffer.

Since:
1.0

length

private int length
The number of bytes this WadByteBuffer contains in it's ByteBuffer.

Since:
1.0
Constructor Detail

WadByteBuffer

public WadByteBuffer(int buffersize)
Creates an empty WadByteBuffer of a set size.

Parameters:
buffersize - the size, in bytes, to allocate for the buffer.
Since:
1.0

WadByteBuffer

public WadByteBuffer(java.nio.channels.FileChannel bufferchannel)
              throws UnableToReadWADFileException
Creates a WadByteBuffer from a FileChannel from the beginning to the end of the channel.

Parameters:
bufferchannel - the FileChannel to read from.
Throws:
UnableToReadWADFileException - if the WAD file cannot be read from or to the specified points.
Since:
1.0

WadByteBuffer

public WadByteBuffer(java.nio.channels.FileChannel bufferchannel,
                     int bufferlength)
              throws UnableToReadWADFileException
Creates a WadByteBuffer from a FileChannel from the beginning of the channel until the number of specified bytes are read.

Parameters:
bufferchannel - the FileChannel to read from.
bufferlength - the number of bytes to read from the starting position of the FileChannel.
Throws:
UnableToReadWADFileException - if the WAD file cannot be read from or to the specified points.
Since:
1.0

WadByteBuffer

public WadByteBuffer(java.nio.channels.FileChannel bufferchannel,
                     int bufferlength,
                     int position)
              throws UnableToReadWADFileException
Creates a WadByteBuffer from a FileChannel from the indicated position until the number of specified bytes are read.

Parameters:
bufferchannel - the FileChannel to read from.
bufferlength - the number of bytes to read from the starting position of the FileChannel.
position - the starting position to read from the FileChannel.
Throws:
UnableToReadWADFileException - if the WAD file cannot be read from or to the specified points.
Since:
1.0

WadByteBuffer

public WadByteBuffer(WadByteBuffer bytebuffer)
Creates a WadByteBuffer from another WadByteBuffer.

Parameters:
bytebuffer - the WadByteBuffer to create the new WadByteBuffer from.
Since:
1.0

WadByteBuffer

public WadByteBuffer(byte[] bytearray)
Creates a WadByteBuffer from an array of bytes.

Parameters:
bytearray - the array of bytes to create the WadByteBuffer from.
Since:
1.0
Method Detail

getArray

private byte[] getArray()
Returns an array of bytes containing the contents of the ByteBuffer.

Returns:
an array of bytes containing the contents of the ByteBuffer.
Since:
1.0

getByte

public byte getByte()
A wrapper class for ByteBuffer's get() method; gets the next byte in the WadByteBuffer.

Returns:
the next byte in the WadByteBuffer.
Since:
1.0

getByte

public byte getByte(int index)
A wrapper class for ByteBuffer's get(int) method; gets the next byte in the WadByteBuffer, starting at the specified position. Unlike the method it wraps, this method increments the position counter.

Parameters:
index - the starting position of the of the WadByteBuffer.
Returns:
the next byte in the WadByteBuffer, from the specified position.
Since:
1.0

getByteBuffer

public WadByteBuffer getByteBuffer(int offset,
                                   int length)
Gets a sub-WadByteBuffer out of the current one, by getting a specified number of bytes starting at a specified position in the buffer.

Parameters:
offset - the starting position for getting bytes in the current WadByteBuffer.
length - the number of bytes to get from the starting position in the WadByteBuffer.
Returns:
a new WadByteBuffer consisting of the bytes from the starting position to the ending position based on the number of bytes to get.
Since:
1.0

getShort

public short getShort()
A wrapper class for ByteBuffer's getShort() method; gets the next short in the WadByteBuffer.

Returns:
the next short in the WadByteBuffer.
Since:
1.0

getShort

public short getShort(int index)
A wrapper class for ByteBuffer's getShort(int) method; gets the next short in the WadByteBuffer, starting at the specified position. Unlike the method it wraps, this method increments the position counter.

Parameters:
index - the starting position of the of the WadByteBuffer.
Returns:
the next short in the WadByteBuffer, from the specified position.
Since:
1.0

getInt

public int getInt()
A wrapper class for ByteBuffer's getInt() method; gets the next integer in the WadByteBuffer.

Returns:
the next integer in the WadByteBuffer.
Since:
1.0

getInt

public int getInt(int index)
A wrapper class for ByteBuffer's getInt(int) method; gets the next integer in the WadByteBuffer, starting at the specified position. Unlike the method it wraps, this method increments the position counter.

Parameters:
index - the starting position of the of the WadByteBuffer.
Returns:
the next integer in the WadByteBuffer, from the specified position.
Since:
1.0

getEightByteString

public java.lang.String getEightByteString(int index)
Gets the next eight bytes in the WadByteBuffer as a String, starting at the specified position. Each byte is a new character.

Parameters:
index - the starting position of the of the WadByteBuffer.
Returns:
the next eight byte String, from the specified position.
Since:
1.0

getEightByteString

public java.lang.String getEightByteString()
Gets the next eight bytes in the WadByteBuffer as a String. Each byte is a new character.

Returns:
the next eight byte String.
Since:
1.0

put

public WadByteBuffer put(byte b)
                  throws java.nio.BufferOverflowException,
                         java.nio.ReadOnlyBufferException
A wrapper class for ByteBuffer's put(byte) method; puts a single byte into the WadByteBuffer.

Parameters:
b - the byte to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.nio.BufferOverflowException - if the current position is not smaller than the limit of the ByteBuffer.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

put

public WadByteBuffer put(int index,
                         byte b)
                  throws java.lang.IndexOutOfBoundsException,
                         java.nio.ReadOnlyBufferException
A wrapper class for ByteBuffer's put(int, byte) method; puts a single byte into the WadByteBuffer at the specified position. Unlike the method it wraps, this method increments the position counter.

Parameters:
index - the position to insert the byte.
b - the byte to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

put

public WadByteBuffer put(WadByteBuffer src)
                  throws java.nio.BufferOverflowException,
                         java.lang.IllegalArgumentException,
                         java.nio.ReadOnlyBufferException
A wrapper class for ByteBuffer's put(ByteBuffer) method; puts a ByteBuffer into the WadByteBuffer.

Parameters:
src - the WadByteBuffer to insert.
Returns:
the current WadByteBuffer.
Throws:
java.nio.BufferOverflowException - if the current position is not smaller than the limit of the ByteBuffer.
java.lang.IllegalArgumentException - if the source buffer and this buffer are the same.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putShort

public WadByteBuffer putShort(short value)
                       throws java.lang.IndexOutOfBoundsException,
                              java.nio.ReadOnlyBufferException
A wrapper class for ByteBuffer's putShort(short) method; puts a short into the WadByteBuffer.

Parameters:
value - the short to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putShort

public WadByteBuffer putShort(int index,
                              short value)
                       throws java.lang.IndexOutOfBoundsException,
                              java.nio.ReadOnlyBufferException
A wrapper class for ByteBuffer's putShort(short) method; puts a short into the WadByteBuffer. Unlike the method it wraps, this method increments the position counter.

Parameters:
index - the position to insert the value.
value - the short to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putInt

public WadByteBuffer putInt(int value)
                     throws java.lang.IndexOutOfBoundsException,
                            java.nio.ReadOnlyBufferException
A wrapper class for ByteBuffer's putInt(int) method; puts an integer into the WadByteBuffer.

Parameters:
value - the integer to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putInt

public WadByteBuffer putInt(int index,
                            int value)
                     throws java.lang.IndexOutOfBoundsException,
                            java.nio.ReadOnlyBufferException
A wrapper class for ByteBuffer's putInt(int) method; puts an integer into the WadByteBuffer. Unlike the method it wraps, this method increments the position counter.

Parameters:
index - the position to insert the value.
value - the integer to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putEightByteString

public WadByteBuffer putEightByteString(int index,
                                        java.lang.String value)
                                 throws java.lang.IndexOutOfBoundsException,
                                        java.nio.ReadOnlyBufferException
Puts eight bytes in the WadByteBuffer as a String at the specified position. Each byte is a new character.

Parameters:
index - the position to insert the value.
value - the String to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putEightByteString

public WadByteBuffer putEightByteString(java.lang.String value)
                                 throws java.lang.IndexOutOfBoundsException,
                                        java.nio.ReadOnlyBufferException
Puts eight bytes in the WadByteBuffer as a String. Each byte is a new character.

Parameters:
value - the String to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putEightByteString

public WadByteBuffer putEightByteString(int index,
                                        char[] value)
                                 throws java.lang.IndexOutOfBoundsException,
                                        java.nio.ReadOnlyBufferException
Puts eight bytes in the WadByteBuffer as an array of characters, at the specified position. Each byte is a new character.

Parameters:
index - the position to insert the value.
value - the character array to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

putEightByteString

public WadByteBuffer putEightByteString(char[] value)
                                 throws java.lang.IndexOutOfBoundsException,
                                        java.nio.ReadOnlyBufferException
Puts eight bytes in the WadByteBuffer as an array of characters. Each byte is a new character.

Parameters:
value - the character array to insert into the WadByteBuffer.
Returns:
the current WadByteBuffer.
Throws:
java.lang.IndexOutOfBoundsException - if index is not positive or out of the ByteBuffer's limit.
java.nio.ReadOnlyBufferException - if the ByteBuffer cannot be written to.
Since:
1.0

hasRemaining

public boolean hasRemaining()
A wrapper class for ByteBuffer's hasRemaining() method; returns true if the WadByteBuffer has any values left past the current position.

Returns:
true if the WadByteBuffer has any values left past the current position, otherwise false.
Since:
1.0

getPosition

public int getPosition()
A wrapper class for ByteBuffer's position() method; returns the WadByteBuffer's position.

Returns:
the position of the WadByteBuffer.
Since:
1.0

setPosition

public WadByteBuffer setPosition(int index)
                          throws java.lang.IllegalArgumentException
A wrapper class for ByteBuffer's position(int) method; sets the WadByteBuffer's position to the specified integer and returns the WadByteBuffer object that called it.

Parameters:
index - the integer to set the WadByteBuffer's position to.
Returns:
the WadByteBuffer object that called it.
Throws:
java.lang.IllegalArgumentException - if the index is negative or larger than the current limit.
Since:
1.0

getLength

public int getLength()
Returns the length of the WadByteBuffer.

Returns:
the length of the WadByteBuffer.
Since:
1.0

getCapacity

public int getCapacity()
Returns the capacity of the ByteBuffer.

Returns:
the capacity of the ByteBuffer.
Since:
1.0

getByteBuffer

public java.nio.ByteBuffer getByteBuffer()
Returns the backing ByteBuffer of the WadByteBuffer.

Returns:
the backing ByteBuffer of the WadByteBuffer.
Since:
1.0

writeToFile

public boolean writeToFile(java.nio.channels.FileChannel filechannel)
                    throws java.io.IOException
Writes this WadByteBuffer's data to the specified channel.

Parameters:
filechannel - the FileChannel to write to.
Returns:
true if the data is successfully written.
Throws:
java.io.IOException - if the data cannot be written to the file.
Since:
1.0

writeToFile

public boolean writeToFile(java.nio.channels.FileChannel filechannel,
                           long position)
                    throws java.io.IOException
Writes this WadByteBuffer's data to the specified channel, at the specified position.

Parameters:
filechannel - the FileChannel to write to.
position - the position in the file to start writing the data.
Returns:
true if the data is successfully written.
Throws:
java.io.IOException - if the data cannot be written to the file.
Since:
1.0

alterBufferSize

public boolean alterBufferSize(int newsize)
Changes the size of the WadByteBuffer's backing ByteBuffer.

Parameters:
newsize - the size the new ByteBuffer should be.
Returns:
true if completed successfully.
Since:
1.0

convertToEightByteString

public static java.lang.String convertToEightByteString(java.lang.String string)
Converts a String to a new eight byte String by padding Strings less than eight characters and truncating Strings greater than eight characters. All the letters are converted to uppercase and all illegal characters are trimmed out. The legal characters are capital A through Z and 0 through 9 along with "[", "]", "-", "_", "\" and the null character.

Parameters:
string - the String to convert to an eight byte String.
Returns:
the new eight byte String.
Since:
1.0

jwadlib WAD Library Extending API
Version 1.0 Alpha 1
Intended for developers wishing to extend jwadlib, not implement it.

© 2008 Samuel insertwackynamehere Horwitz.
jwadlib WAD Library is released under the GNU Lesser Public License with the documentation freely written into the source code. This generated output it provided for the benefit of users. All the information contained is available as part of the downloaded library.