@Test public void testWriteChunksToStream() throws IOException { final byte[] data = new byte[256]; int counter = 0; for (int i = 0; i < data.length; i++) { data[i] = (byte) counter++; } byte[] header = new byte[9]; testWithGivenChunkSize(data, header, 16); testWithGivenChunkSize(data, header, 10); testWithGivenChunkSize(data, header, 13); }
protected static void writeChunksToStream(byte[] data, byte[] dataHeader, int lengthOffset, int maxChunkLength, OutputStream os) throws IOException { int dataLength = data.length; int numFullChunks = dataLength / maxChunkLength; int lastChunkLength = dataLength % maxChunkLength; int headerLen = dataHeader.length - lengthOffset; if (headerLen == 2) { headerLen = 0; } byte[] len; int off = 0; if (numFullChunks > 0) { len = BinaryUtils.convert(headerLen + maxChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) { os.write(dataHeader); os.write(data, off, maxChunkLength); } } if (lastChunkLength > 0) { len = BinaryUtils.convert(headerLen + lastChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; os.write(dataHeader); os.write(data, off, lastChunkLength); } }
AbstractAFPObject implements Streamable { protected static void writeChunksToStream(byte[] data, byte[] dataHeader, int lengthOffset, int maxChunkLength, OutputStream os) throws IOException { int dataLength = data.length; int numFullChunks = dataLength / maxChunkLength; int lastChunkLength = dataLength % maxChunkLength; int headerLen = dataHeader.length - lengthOffset; if (headerLen == 2) { headerLen = 0; } byte[] len; int off = 0; if (numFullChunks > 0) { len = BinaryUtils.convert(headerLen + maxChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) { os.write(dataHeader); os.write(data, off, maxChunkLength); } } if (lastChunkLength > 0) { len = BinaryUtils.convert(headerLen + lastChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; os.write(dataHeader); os.write(data, off, lastChunkLength); } } }
AbstractAFPObject implements Streamable { protected static void writeChunksToStream(byte[] data, byte[] dataHeader, int lengthOffset, int maxChunkLength, OutputStream os) throws IOException { int dataLength = data.length; int numFullChunks = dataLength / maxChunkLength; int lastChunkLength = dataLength % maxChunkLength; int headerLen = dataHeader.length - lengthOffset; if (headerLen == 2) { headerLen = 0; } byte[] len; int off = 0; if (numFullChunks > 0) { len = BinaryUtils.convert(headerLen + maxChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) { os.write(dataHeader); os.write(data, off, maxChunkLength); } } if (lastChunkLength > 0) { len = BinaryUtils.convert(headerLen + lastChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; os.write(dataHeader); os.write(data, off, lastChunkLength); } }  }
AbstractAFPObject implements Streamable { protected static void writeChunksToStream(byte[] data, byte[] dataHeader, int lengthOffset, int maxChunkLength, OutputStream os) throws IOException { int dataLength = data.length; int numFullChunks = dataLength / maxChunkLength; int lastChunkLength = dataLength % maxChunkLength; int headerLen = dataHeader.length - lengthOffset; if (headerLen == 2) { headerLen = 0; } byte[] len; int off = 0; if (numFullChunks > 0) { len = BinaryUtils.convert(headerLen + maxChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) { os.write(dataHeader); os.write(data, off, maxChunkLength); } } if (lastChunkLength > 0) { len = BinaryUtils.convert(headerLen + lastChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; os.write(dataHeader); os.write(data, off, lastChunkLength); } }   }
AbstractAFPObject implements Streamable { protected static void writeChunksToStream(byte[] data, byte[] dataHeader, int lengthOffset, int maxChunkLength, OutputStream os) throws IOException { int dataLength = data.length; int numFullChunks = dataLength / maxChunkLength; int lastChunkLength = dataLength % maxChunkLength; int headerLen = dataHeader.length - lengthOffset; if (headerLen == 2) { headerLen = 0; } byte[] len; int off = 0; if (numFullChunks > 0) { len = BinaryUtils.convert(headerLen + maxChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) { os.write(dataHeader); os.write(data, off, maxChunkLength); } } if (lastChunkLength > 0) { len = BinaryUtils.convert(headerLen + lastChunkLength, 2); dataHeader[lengthOffset] = len[0]; dataHeader[lengthOffset + 1] = len[1]; os.write(dataHeader); os.write(data, off, lastChunkLength); } }    }