ScsiResponseDataSegment { public ByteBuffer serialize () { final int size = uncroppedSize(); if (size == 0) return ByteBuffer.allocate(0); int senseLength; if (senseData == null) senseLength = 0; else senseLength = senseData.size(); final ByteBuffer buffer = ByteBuffer.allocate(size); ReadWrite.writeTwoByteInt(buffer, senseLength, 0); if (senseData != null) senseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH); if (responseData != null) responseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH + senseLength); if (allocationLength > 0 && buffer.capacity() > allocationLength) { buffer.position(0); buffer.limit(allocationLength); final ByteBuffer croppedBuffer = ByteBuffer.allocate(allocationLength); croppedBuffer.put(buffer); return croppedBuffer; } if (LOGGER.isDebugEnabled()) LOGGER.debug("SCSI Response Data Segment:\n" + Debug.byteBufferToString(buffer)); return buffer; } private  ScsiResponseDataSegment();  ScsiResponseDataSegment(final SenseData senseData, final int allocationLength);  ScsiResponseDataSegment(final IResponseData responseData, final int allocationLength); private  ScsiResponseDataSegment(final SenseData senseData, final IResponseData responseData, final int allocationLength); ByteBuffer serialize(); int uncroppedSize(); boolean getResidualOverflow(); int getResidualCount(); static final ScsiResponseDataSegment EMPTY_DATA_SEGMENT; }
@Test public void testNoneEmpty () { nonEmpty.serialize(); }
@Test public void testEmpty () { ScsiResponseDataSegment.EMPTY_DATA_SEGMENT.serialize(); }