Java Code Examples for javax.imageio.stream.ImageOutputStream#writeLong()

The following examples show how to use javax.imageio.stream.ImageOutputStream#writeLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChannelImageOutputStreamTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes {@link ChannelImageOutputStream#reset()} {@code nbMarks} times and verify that the stream position
 * is the expected one. This method will then write random values at those positions, and finally compare the
 * stream content.
 */
private void compareMarks(int nbMarks) throws IOException {
    final ImageOutputStream referenceStream = (ImageOutputStream) this.referenceStream;
    while (--nbMarks >= 0) {
        referenceStream.reset();
        testedStream.reset();
        assertEquals(referenceStream.getBitOffset(),      testedStream.getBitOffset());
        assertEquals(referenceStream.getStreamPosition(), testedStream.getStreamPosition());
        final long v = random.nextLong();
        referenceStream.writeLong(v);
        testedStream.writeLong(v);
    }
    /*
     * Verify that we have no remaining marks, and finally compare stream content.
     */
    try {
        testedStream.reset();
        fail("Expected no remaining marks.");
    } catch (InvalidMarkException e) {
        // This is the expected exception.
    }
    assertStreamContentEquals();
}
 
Example 2
Source File: Box.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
/** Writes this box instance into a <code>ImageOutputStream</code>. */
public void write(ImageOutputStream ios) throws IOException {
    ios.writeInt(length);
    ios.writeInt(type);
    if (length == 1) {
        ios.writeLong(extraLength);
        ios.write(data, 0, (int)extraLength);
    } else if (data != null)
        ios.write(data, 0, length);
}
 
Example 3
Source File: ChannelImageOutputStreamTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link ChannelImageOutputStream#flushBefore(long)}.
 *
 * @throws IOException should never happen since we read and write in memory only.
 */
@Test
@DependsOnMethod("testMarkAndReset")
public void testFlushBefore() throws IOException {
    final int N = 50; // Number of long values to write.
    initialize("testFlushBefore", N*Long.BYTES, 200);
    final ImageOutputStream referenceStream = (ImageOutputStream) this.referenceStream;
    for (int i=0; i<N; i++) {
        switch (i) {
            case 20:
            case 30:
            case 40:
            case 45: {
                referenceStream.mark();
                testedStream.mark();
                break;
            }
            case 10: {
                referenceStream.flushBefore(5 * Long.BYTES);
                testedStream.flushBefore(5 * Long.BYTES);
                break;
            }
            case 35: {
                referenceStream.flushBefore(32 * Long.BYTES);
                testedStream.flushBefore(32 * Long.BYTES);
                break;
            }
        }
        final long v = random.nextLong();
        referenceStream.writeLong(v);
        testedStream.writeLong(v);
    }
    compareMarks(2);
}