int type = getTransferType(); int bitnum = dataBitOffset + x * pixelBitStride; int index = y * scanlineStride + (bitnum / dataElementSize); int shift = dataElementSize - (bitnum & (dataElementSize - 1)) - pixelBitStride; int element = data.getElem(index); element &= ~(bitMask << shift);  switch (type) {  case DataBuffer.TYPE_BYTE :  byte[] barray = (byte[]) obj; element |= (((barray[0]) & 0xff) & bitMask) << shift; data.setElem(index, element); break;  case DataBuffer.TYPE_USHORT :  short[] sarray = (short[]) obj; element |= (((sarray[0]) & 0xffff) & bitMask) << shift; data.setElem(index, element); break;  case DataBuffer.TYPE_INT :  int[] iarray = (int[]) obj; element |= (iarray[0] & bitMask) << shift; data.setElem(index, element); break; } }
int offset = getOffset(x, y);  try { switch (transferType) { case DataBuffer.TYPE_BYTE: { DataBufferByte out = (DataBufferByte) data; byte[] in = (byte[]) obj; out.getData()[offset] = in[0]; return; } case DataBuffer.TYPE_USHORT: { DataBufferUShort out = (DataBufferUShort) data; short[] in = (short[]) obj; out.getData()[offset] = in[0]; return; } case DataBuffer.TYPE_INT: { DataBufferInt out = (DataBufferInt) data; int[] in = (int[]) obj; out.getData()[offset] = in[0]; return; } default: throw new ClassCastException("Unsupported data type"); } } catch (ArrayIndexOutOfBoundsException aioobe) { String msg = "While writing data elements" + ", x="+x+", y="+y+ ", width="+width+", height="+height+ ", scanlineStride="+scanlineStride+ ", offset="+offset+ ", data.getSize()="+data.getSize()+ ", data.getOffset()="+data.getOffset()+ ": " + aioobe; throw new ArrayIndexOutOfBoundsException(msg); } }
	public void setDataElements(int x, int y, Object obj, DataBuffer data) {		if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {			throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!");		}		int type = getTransferType();		int bitnum = dataBitOffset + x * pixelBitStride;		int index = y * scanlineStride + (bitnum / dataElementSize);		int shift = dataElementSize - (bitnum & (dataElementSize - 1)) - pixelBitStride;		int element = data.getElem(index);		element &= ~(bitMask << shift);		switch (type) {			case DataBuffer.TYPE_BYTE :				byte[] barray = (byte[]) obj;				element |= (((barray[0]) & 0xff) & bitMask) << shift;				data.setElem(index, element);				break;			case DataBuffer.TYPE_USHORT :				short[] sarray = (short[]) obj;				element |= (((sarray[0]) & 0xffff) & bitMask) << shift;				data.setElem(index, element);				break;			case DataBuffer.TYPE_INT :				int[] iarray = (int[]) obj;				element |= (iarray[0] & bitMask) << shift;				data.setElem(index, element);				break;		}	}