APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.image

public abstract Class DataBuffer

extends Object
Class Inheritance
Known Direct Subclasses
java.awt.image.DataBufferByte, java.awt.image.DataBufferDouble, java.awt.image.DataBufferFloat, java.awt.image.DataBufferInt, java.awt.image.DataBufferShort, java.awt.image.DataBufferUShort, sun.awt.image.DataBufferNative
Imports
java.lang.annotation.Native, sun.awt.image.SunWritableRaster, sun.java2d.StateTrackable.State, .StateTrackableDelegate

This class exists to wrap one or more data arrays. Each data array in the DataBuffer is referred to as a bank. Accessor methods for getting and setting elements of the DataBuffer's banks exist with and without a bank specifier. The methods without a bank specifier use the default 0th bank. The DataBuffer can optionally take an offset per bank, so that data in an existing array can be used even if the interesting data doesn't start at array location zero. Getting or setting the 0th element of a bank, uses the (0+offset)th element of the array. The size field specifies how much of the data array is available for use. Size + offset for a given bank should never be greater than the length of the associated data array. The data type of a data buffer indicates the type of the data array(s) and may also indicate additional semantics, e.g. storing unsigned 8-bit data in elements of a byte array. The data type may be TYPE_UNDEFINED or one of the types defined below. Other types may be added in the future. Generally, an object of class DataBuffer will be cast down to one of its data type specific subclasses to access data type specific methods for improved performance. Currently, the Java 2D(tm) API image classes use TYPE_BYTE, TYPE_USHORT, TYPE_INT, TYPE_SHORT, TYPE_FLOAT, and TYPE_DOUBLE DataBuffers to store image data.
See Also
java.awt.image.Raster, java.awt.image.SampleModel

Field Summary

Modifier and TypeField and Description
protected int
banks

The number of banks in this DataBuffer.

protected int
dataType

The data type of this DataBuffer.

private static final int[]
dataTypeSize

Size of the data types indexed by DataType tags defined above.

protected int
offset

Offset into default (first) bank from which to get the first element.

protected int[]
offsets

Offsets into all banks.

protected int
size

Usable size of all banks.

pack-priv StateTrackableDelegate
public static final int
TYPE_BYTE

Tag for unsigned byte data.

public static final int
TYPE_DOUBLE

Tag for double data.

public static final int
TYPE_FLOAT

Tag for float data.

public static final int
TYPE_INT

Tag for int data.

public static final int
TYPE_SHORT

Tag for signed short data.

public static final int
TYPE_UNDEFINED

Tag for undefined data.

public static final int
TYPE_USHORT

Tag for unsigned short data.

Constructor Summary

AccessConstructor and Description
protected
DataBuffer(int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
)

Constructs a DataBuffer containing one bank of the specified data type and size.

pack-priv
DataBuffer(StateTrackable.State
the initial State state of the data
initialState
,
int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
)

Constructs a DataBuffer containing one bank of the specified data type and size with the indicated initial State.

protected
DataBuffer(int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
,
int
the number of banks in this DataBuffer
numBanks
)

Constructs a DataBuffer containing the specified number of banks.

pack-priv
DataBuffer(StateTrackable.State
the initial State state of the data
initialState
,
int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
,
int
the number of banks in this DataBuffer
numBanks
)

Constructs a DataBuffer containing the specified number of banks with the indicated initial State.

protected
DataBuffer(int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
,
int
the number of banks in this DataBuffer
numBanks
,
int
the offset for each bank
offset
)

Constructs a DataBuffer that contains the specified number of banks.

pack-priv
DataBuffer(StateTrackable.State
the initial State state of the data
initialState
,
int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
,
int
the number of banks in this DataBuffer
numBanks
,
int
the offset for each bank
offset
)

Constructs a DataBuffer that contains the specified number of banks with the indicated initial State.

protected
DataBuffer(int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
,
int
the number of banks in this DataBuffer
numBanks
,
int[]
an array containing an offset for each bank.
offsets
)

Constructs a DataBuffer which contains the specified number of banks.

pack-priv
DataBuffer(StateTrackable.State
the initial State state of the data
initialState
,
int
the data type of this DataBuffer
dataType
,
int
the size of the banks
size
,
int
the number of banks in this DataBuffer
numBanks
,
int[]
an array containing an offset for each bank.
offsets
)

Constructs a DataBuffer which contains the specified number of banks with the indicated initial State.

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
checkArraySize(int size, int arrayLen)

pack-priv static void
checkArraySize(int size, int offset, int arrayLen)

pack-priv final void
checkBank(int bank)

pack-priv static void
checkBankSize(int bankIndex, int size, int offset, int arrayLen)

pack-priv final void
checkIndex(int i)

pack-priv final void
checkIndex(int bank, int i)

pack-priv static void
checkNumBanks(int numBanks)

pack-priv static void
checkOffset(int offset)

pack-priv static void
checkSize(int size)

private static boolean
checkSizeAndOffset(int size, int offset, int arrayLen)

public int

Returns:

the data type of this DataBuffer.
getDataType
()

Returns the data type of this DataBuffer.

public static int

Returns:

the size of the data type
getDataTypeSize
(int
the value of one of the defined datatype tags
type
)

Returns the size (in bits) of the data type, given a datatype tag.

public int

Returns:

the data array element at the specified index.
getElem
(int
the index of the requested data array element
i
)

Returns the requested data array element from the first (default) bank as an integer.

public abstract int

Returns:

the data array element at the specified index from the specified bank at the specified index.
getElem
(int
the specified bank
bank
,
int
the index of the requested data array element
i
)

Returns the requested data array element from the specified bank as an integer.

public double

Returns:

a double value representing the element at the specified index in the data array.
getElemDouble
(int
the specified index
i
)

Returns the requested data array element from the first (default) bank as a double.

public double

Returns:

a double value representing the element from the specified bank at the specified index in the data array.
getElemDouble
(int
the specified bank
bank
,
int
the specified index
i
)

Returns the requested data array element from the specified bank as a double.

public float

Returns:

a float value representing the data array element at the specified index.
getElemFloat
(int
the index of the requested data array element
i
)

Returns the requested data array element from the first (default) bank as a float.

public float

Returns:

a float value representing the data array element from the specified bank at the specified index.
getElemFloat
(int
the specified bank
bank
,
int
the index of the requested data array element
i
)

Returns the requested data array element from the specified bank as a float.

public int

Returns:

the number of banks.
getNumBanks
()

Returns the number of banks in this DataBuffer.

public int

Returns:

the offset of the default bank.
getOffset
()

Returns the offset of the default bank in array elements.

public int[]

Returns:

the offsets of all banks.
getOffsets
()

Returns the offsets (in array elements) of all the banks.

public int

Returns:

the size of all banks.
getSize
()

Returns the size (in array elements) of all banks.

public void
setElem(int
the specified index into the data array
i
,
int
the data to set the element at the specified index in the data array
val
)

Sets the requested data array element in the first (default) bank from the given integer.

public abstract void
setElem(int
the specified bank
bank
,
int
the specified index into the data array
i
,
int
the data to set the element in the specified bank at the specified index in the data array
val
)

Sets the requested data array element in the specified bank from the given integer.

public void
setElemDouble(int
the specified index
i
,
double
the value to set the element at the specified index in the data array
val
)

Sets the requested data array element in the first (default) bank from the given double.

public void
setElemDouble(int
the specified bank
bank
,
int
the specified index
i
,
double
the value to set the element in the specified bank at the specified index of the data array
val
)

Sets the requested data array element in the specified bank from the given double.

public void
setElemFloat(int
the specified index
i
,
float
the value to set the element at the specified index in the data array
val
)

Sets the requested data array element in the first (default) bank from the given float.

public void
setElemFloat(int
the specified bank
bank
,
int
the specified index
i
,
float
the value to set the element in the specified bank at the specified index in the data array
val
)

Sets the requested data array element in the specified bank from the given float.

pack-priv static int[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

banksback to summary
protected int banks

The number of banks in this DataBuffer.

dataTypeback to summary
protected int dataType

The data type of this DataBuffer.

dataTypeSizeback to summary
private static final int[] dataTypeSize

Size of the data types indexed by DataType tags defined above.

offsetback to summary
protected int offset

Offset into default (first) bank from which to get the first element.

offsetsback to summary
protected int[] offsets

Offsets into all banks.

sizeback to summary
protected int size

Usable size of all banks.

theTrackableback to summary
pack-priv StateTrackableDelegate theTrackable
TYPE_BYTEback to summary
public static final int TYPE_BYTE

Tag for unsigned byte data.

Annotations
@Native
TYPE_DOUBLEback to summary
public static final int TYPE_DOUBLE

Tag for double data.

Annotations
@Native
TYPE_FLOATback to summary
public static final int TYPE_FLOAT

Tag for float data.

Annotations
@Native
TYPE_INTback to summary
public static final int TYPE_INT

Tag for int data.

Annotations
@Native
TYPE_SHORTback to summary
public static final int TYPE_SHORT

Tag for signed short data.

Annotations
@Native
TYPE_UNDEFINEDback to summary
public static final int TYPE_UNDEFINED

Tag for undefined data.

Annotations
@Native
TYPE_USHORTback to summary
public static final int TYPE_USHORT

Tag for unsigned short data.

Annotations
@Native

Constructor Detail

DataBufferback to summary
protected DataBuffer(int dataType, int size)

Constructs a DataBuffer containing one bank of the specified data type and size.

Parameters
dataType:int

the data type of this DataBuffer

size:int

the size of the banks

Exceptions
IllegalArgumentException:
if size is less than or equal to zero.
DataBufferback to summary
pack-priv DataBuffer(StateTrackable.State initialState, int dataType, int size)

Constructs a DataBuffer containing one bank of the specified data type and size with the indicated initial State.

Parameters
initialState:StateTrackable.State

the initial State state of the data

dataType:int

the data type of this DataBuffer

size:int

the size of the banks

Exceptions
IllegalArgumentException:
if size is less than or equal to zero.
Since
1.7
DataBufferback to summary
protected DataBuffer(int dataType, int size, int numBanks)

Constructs a DataBuffer containing the specified number of banks. Each bank has the specified size and an offset of 0.

Parameters
dataType:int

the data type of this DataBuffer

size:int

the size of the banks

numBanks:int

the number of banks in this DataBuffer

Exceptions
IllegalArgumentException:
if size or numBanks is less than or equal to zero.
DataBufferback to summary
pack-priv DataBuffer(StateTrackable.State initialState, int dataType, int size, int numBanks)

Constructs a DataBuffer containing the specified number of banks with the indicated initial State. Each bank has the specified size and an offset of 0.

Parameters
initialState:StateTrackable.State

the initial State state of the data

dataType:int

the data type of this DataBuffer

size:int

the size of the banks

numBanks:int

the number of banks in this DataBuffer

Exceptions
IllegalArgumentException:
if size or numBanks is less than or equal to zero.
Since
1.7
DataBufferback to summary
protected DataBuffer(int dataType, int size, int numBanks, int offset)

Constructs a DataBuffer that contains the specified number of banks. Each bank has the specified datatype, size and offset.

Parameters
dataType:int

the data type of this DataBuffer

size:int

the size of the banks

numBanks:int

the number of banks in this DataBuffer

offset:int

the offset for each bank

Exceptions
IllegalArgumentException:
  • if size or numBanks is less than or equal to zero.
  • if offset is less than zero.
DataBufferback to summary
pack-priv DataBuffer(StateTrackable.State initialState, int dataType, int size, int numBanks, int offset)

Constructs a DataBuffer that contains the specified number of banks with the indicated initial State. Each bank has the specified datatype, size and offset.

Parameters
initialState:StateTrackable.State

the initial State state of the data

dataType:int

the data type of this DataBuffer

size:int

the size of the banks

numBanks:int

the number of banks in this DataBuffer

offset:int

the offset for each bank

Exceptions
IllegalArgumentException:
  • if size or numBanks is less than or equal to zero.
  • if offset is less than zero.
Since
1.7
DataBufferback to summary
protected DataBuffer(int dataType, int size, int numBanks, int[] offsets)

Constructs a DataBuffer which contains the specified number of banks. Each bank has the specified datatype and size. The offset for each bank is specified by its respective entry in the offsets array.

Parameters
dataType:int

the data type of this DataBuffer

size:int

the size of the banks

numBanks:int

the number of banks in this DataBuffer

offsets:int[]

an array containing an offset for each bank.

Exceptions
IllegalArgumentException:
  • if size or numBanks is less than or equal to zero.
  • if any element of offsets is less than zero.
NullPointerException:
if offsets is null.
ArrayIndexOutOfBoundsException:
if numBanks does not equal the length of offsets
DataBufferback to summary
pack-priv DataBuffer(StateTrackable.State initialState, int dataType, int size, int numBanks, int[] offsets)

Constructs a DataBuffer which contains the specified number of banks with the indicated initial State. Each bank has the specified datatype and size. The offset for each bank is specified by its respective entry in the offsets array.

Parameters
initialState:StateTrackable.State

the initial State state of the data

dataType:int

the data type of this DataBuffer

size:int

the size of the banks

numBanks:int

the number of banks in this DataBuffer

offsets:int[]

an array containing an offset for each bank.

Exceptions
IllegalArgumentException:
  • if size or numBanks is less than or equal to zero.
  • if any element of offsets is less than zero.
NullPointerException:
if offsets is null.
ArrayIndexOutOfBoundsException:
if numBanks does not equal the length of offsets
Since
1.7

Method Detail

checkArraySizeback to summary
pack-priv static void checkArraySize(int size, int arrayLen)
checkArraySizeback to summary
pack-priv static void checkArraySize(int size, int offset, int arrayLen)
checkBankback to summary
pack-priv final void checkBank(int bank)
checkBankSizeback to summary
pack-priv static void checkBankSize(int bankIndex, int size, int offset, int arrayLen)
checkIndexback to summary
pack-priv final void checkIndex(int i)
checkIndexback to summary
pack-priv final void checkIndex(int bank, int i)
checkNumBanksback to summary
pack-priv static void checkNumBanks(int numBanks)
checkOffsetback to summary
pack-priv static void checkOffset(int offset)
checkSizeback to summary
pack-priv static void checkSize(int size)
checkSizeAndOffsetback to summary
private static boolean checkSizeAndOffset(int size, int offset, int arrayLen)
getDataTypeback to summary
public int getDataType()

Returns the data type of this DataBuffer.

Returns:int

the data type of this DataBuffer.

getDataTypeSizeback to summary
public static int getDataTypeSize(int type)

Returns the size (in bits) of the data type, given a datatype tag.

Parameters
type:int

the value of one of the defined datatype tags

Returns:int

the size of the data type

Exceptions
IllegalArgumentException:
if type is less than zero or greater than TYPE_DOUBLE
getElemback to summary
public int getElem(int i)

Returns the requested data array element from the first (default) bank as an integer.

Parameters
i:int

the index of the requested data array element

Returns:int

the data array element at the specified index.

Exceptions
ArrayIndexOutOfBoundsException:
if (i + getOffset()) is not a valid index.
See Also
setElem(int, int), setElem(int, int, int)
getElemback to summary
public abstract int getElem(int bank, int i)

Returns the requested data array element from the specified bank as an integer.

Parameters
bank:int

the specified bank

i:int

the index of the requested data array element

Returns:int

the data array element at the specified index from the specified bank at the specified index.

Exceptions
ArrayIndexOutOfBoundsException:
if bank is not a valid bank index, or (i + getOffsets()[bank]) is not a valid index into the bank.
See Also
setElem(int, int), setElem(int, int, int)
getElemDoubleback to summary
public double getElemDouble(int i)

Returns the requested data array element from the first (default) bank as a double. The implementation in this class is to cast getElem(int) to a double. Subclasses can override this method if another implementation is needed.

Parameters
i:int

the specified index

Returns:double

a double value representing the element at the specified index in the data array.

Exceptions
ArrayIndexOutOfBoundsException:
if (i + getOffset()) is not a valid index.
See Also
setElemDouble(int, double), setElemDouble(int, int, double)
getElemDoubleback to summary
public double getElemDouble(int bank, int i)

Returns the requested data array element from the specified bank as a double. The implementation in this class is to cast getElem(bank, i) to a double. Subclasses may override this method if another implementation is needed.

Parameters
bank:int

the specified bank

i:int

the specified index

Returns:double

a double value representing the element from the specified bank at the specified index in the data array.

Exceptions
ArrayIndexOutOfBoundsException:
if bank is not a valid bank index, or (i + getOffsets()[bank]) is not a valid index into the bank.
See Also
setElemDouble(int, double), setElemDouble(int, int, double)
getElemFloatback to summary
public float getElemFloat(int i)

Returns the requested data array element from the first (default) bank as a float. The implementation in this class is to cast getElem(i) to a float. Subclasses may override this method if another implementation is needed.

Parameters
i:int

the index of the requested data array element

Returns:float

a float value representing the data array element at the specified index.

Exceptions
ArrayIndexOutOfBoundsException:
if (i + getOffset()) is not a valid index.
See Also
setElemFloat(int, float), setElemFloat(int, int, float)
getElemFloatback to summary
public float getElemFloat(int bank, int i)

Returns the requested data array element from the specified bank as a float. The implementation in this class is to cast getElem(int, int) to a float. Subclasses can override this method if another implementation is needed.

Parameters
bank:int

the specified bank

i:int

the index of the requested data array element

Returns:float

a float value representing the data array element from the specified bank at the specified index.

Exceptions
ArrayIndexOutOfBoundsException:
if bank is not a valid bank index, or (i + getOffsets()[bank]) is not a valid index into the bank.
See Also
setElemFloat(int, float), setElemFloat(int, int, float)
getNumBanksback to summary
public int getNumBanks()

Returns the number of banks in this DataBuffer.

Returns:int

the number of banks.

getOffsetback to summary
public int getOffset()

Returns the offset of the default bank in array elements.

Returns:int

the offset of the default bank.

getOffsetsback to summary
public int[] getOffsets()

Returns the offsets (in array elements) of all the banks.

Returns:int[]

the offsets of all banks.

getSizeback to summary
public int getSize()

Returns the size (in array elements) of all banks.

Returns:int

the size of all banks.

setElemback to summary
public void setElem(int i, int val)

Sets the requested data array element in the first (default) bank from the given integer.

Parameters
i:int

the specified index into the data array

val:int

the data to set the element at the specified index in the data array

Exceptions
ArrayIndexOutOfBoundsException:
if (i + getOffset()) is not a valid index.
See Also
getElem(int), getElem(int, int)
setElemback to summary
public abstract void setElem(int bank, int i, int val)

Sets the requested data array element in the specified bank from the given integer.

Parameters
bank:int

the specified bank

i:int

the specified index into the data array

val:int

the data to set the element in the specified bank at the specified index in the data array

Exceptions
ArrayIndexOutOfBoundsException:
if bank is not a valid bank index, or (i + getOffsets()[bank]) is not a valid index into the bank.
See Also
getElem(int), getElem(int, int)
setElemDoubleback to summary
public void setElemDouble(int i, double val)

Sets the requested data array element in the first (default) bank from the given double. The implementation in this class is to cast val to an int and call setElem(int, int). Subclasses can override this method if another implementation is needed.

Parameters
i:int

the specified index

val:double

the value to set the element at the specified index in the data array

Exceptions
ArrayIndexOutOfBoundsException:
if (i + getOffset()) is not a valid index.
See Also
getElemDouble(int), getElemDouble(int, int)
setElemDoubleback to summary
public void setElemDouble(int bank, int i, double val)

Sets the requested data array element in the specified bank from the given double. The implementation in this class is to cast val to an int and call setElem(int, int). Subclasses can override this method if another implementation is needed.

Parameters
bank:int

the specified bank

i:int

the specified index

val:double

the value to set the element in the specified bank at the specified index of the data array

Exceptions
ArrayIndexOutOfBoundsException:
if bank is not a valid bank index, or (i + getOffsets()[bank]) is not a valid index into the bank.
See Also
getElemDouble(int), getElemDouble(int, int)
setElemFloatback to summary
public void setElemFloat(int i, float val)

Sets the requested data array element in the first (default) bank from the given float. The implementation in this class is to cast val to an int and call setElem(int, int). Subclasses can override this method if another implementation is needed.

Parameters
i:int

the specified index

val:float

the value to set the element at the specified index in the data array

Exceptions
ArrayIndexOutOfBoundsException:
if (i + getOffset()) is not a valid index.
See Also
getElemFloat(int), getElemFloat(int, int)
setElemFloatback to summary
public void setElemFloat(int bank, int i, float val)

Sets the requested data array element in the specified bank from the given float. The implementation in this class is to cast val to an int and call setElem(int, int). Subclasses can override this method if another implementation is needed.

Parameters
bank:int

the specified bank

i:int

the specified index

val:float

the value to set the element in the specified bank at the specified index in the data array

Exceptions
ArrayIndexOutOfBoundsException:
if bank is not a valid bank index, or (i + getOffsets()[bank]) is not a valid index into the bank.
See Also
getElemFloat(int), getElemFloat(int, int)
toIntArrayback to summary
pack-priv static int[] toIntArray(Object obj)