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

The following examples show how to use javax.imageio.stream.ImageOutputStream#getStreamPosition() . 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: WriteBitsTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void verify(ImageOutputStream ios,
                           long expstreampos, int expbitoffset)
    throws IOException, RuntimeException
{
    long actstreampos = ios.getStreamPosition();
    int actbitoffset = ios.getBitOffset();

    if ((actstreampos != expstreampos) ||
        (actbitoffset != expbitoffset))
    {
        System.err.println("Expected stream position: " + expstreampos +
                           " Actual: " + actstreampos);
        System.err.println("Expected bit offset: " + expbitoffset +
                           " Actual: " + actbitoffset);
        throw new RuntimeException("Test failed.");
    }
}
 
Example 2
Source File: WriteBitsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void verify(ImageOutputStream ios,
                           long expstreampos, int expbitoffset)
    throws IOException, RuntimeException
{
    long actstreampos = ios.getStreamPosition();
    int actbitoffset = ios.getBitOffset();

    if ((actstreampos != expstreampos) ||
        (actbitoffset != expbitoffset))
    {
        System.err.println("Expected stream position: " + expstreampos +
                           " Actual: " + actstreampos);
        System.err.println("Expected bit offset: " + expbitoffset +
                           " Actual: " + actbitoffset);
        throw new RuntimeException("Test failed.");
    }
}
 
Example 3
Source File: PNGImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 4
Source File: PNGImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 5
Source File: PNGImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 6
Source File: PNGImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 7
Source File: PNGImageWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 8
Source File: PNGImageWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 9
Source File: PNGImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 10
Source File: PNGImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 11
Source File: PNGImageWriter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 12
Source File: PNGImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 13
Source File: PNGImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 14
Source File: PNGImageWriter.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 15
Source File: PNGImageWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 16
Source File: PNGImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 17
Source File: PNGImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ChunkStream(int type, ImageOutputStream stream) throws IOException {
    this.stream = stream;
    this.startPos = stream.getStreamPosition();

    stream.writeInt(-1); // length, will backpatch
    writeInt(type);
}
 
Example 18
Source File: TIFFIFD.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void writeToStream(ImageOutputStream stream)
    throws IOException {

    int numFields = getNumTIFFFields();
    stream.writeShort(numFields);

    long nextSpace = stream.getStreamPosition() + 12*numFields + 4;

    Iterator<TIFFField> iter = iterator();
    while (iter.hasNext()) {
        TIFFField f = iter.next();

        TIFFTag tag = f.getTag();

        int type = f.getType();
        int count = f.getCount();

        // Deal with unknown tags
        if (type == 0) {
            type = TIFFTag.TIFF_UNDEFINED;
        }
        int size = count*TIFFTag.getSizeOfType(type);

        if (type == TIFFTag.TIFF_ASCII) {
            int chars = 0;
            for (int i = 0; i < count; i++) {
                chars += f.getAsString(i).length() + 1;
            }
            count = chars;
            size = count;
        }

        int tagNumber = f.getTagNumber();
        stream.writeShort(tagNumber);
        stream.writeShort(type);
        stream.writeInt(count);

        // Write a dummy value to fill space
        stream.writeInt(0);
        stream.mark(); // Mark beginning of next field
        stream.skipBytes(-4);

        long pos;

        if (size > 4 || tag.isIFDPointer()) {
            // Ensure IFD or value is written on a word boundary
            nextSpace = (nextSpace + 3) & ~0x3;

            stream.writeInt((int)nextSpace);
            stream.seek(nextSpace);
            pos = nextSpace;

            if (tag.isIFDPointer() && f.hasDirectory()) {
                TIFFIFD subIFD = getDirectoryAsIFD(f.getDirectory());
                subIFD.writeToStream(stream);
                nextSpace = subIFD.lastPosition;
            } else {
                writeTIFFFieldToStream(f, stream);
                nextSpace = stream.getStreamPosition();
            }
        } else {
            pos = stream.getStreamPosition();
            writeTIFFFieldToStream(f, stream);
        }

        // If we are writing the data for the
        // StripByteCounts, TileByteCounts, StripOffsets,
        // TileOffsets, JPEGInterchangeFormat, or
        // JPEGInterchangeFormatLength fields, record the current stream
        // position for backpatching
        if (tagNumber ==
            BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH) {
            this.stripOrTileByteCountsPosition = pos;
        } else if (tagNumber ==
                   BaselineTIFFTagSet.TAG_STRIP_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_TILE_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT) {
            this.stripOrTileOffsetsPosition = pos;
        }

        stream.reset(); // Go to marked position of next field
    }

    this.lastPosition = nextSpace;
}
 
Example 19
Source File: TIFFIFD.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void writeToStream(ImageOutputStream stream)
    throws IOException {

    int numFields = getNumTIFFFields();
    stream.writeShort(numFields);

    long nextSpace = stream.getStreamPosition() + 12*numFields + 4;

    Iterator<TIFFField> iter = iterator();
    while (iter.hasNext()) {
        TIFFField f = iter.next();

        TIFFTag tag = f.getTag();

        int type = f.getType();
        int count = f.getCount();

        // Deal with unknown tags
        if (type == 0) {
            type = TIFFTag.TIFF_UNDEFINED;
        }
        int size = count*TIFFTag.getSizeOfType(type);

        if (type == TIFFTag.TIFF_ASCII) {
            int chars = 0;
            for (int i = 0; i < count; i++) {
                chars += f.getAsString(i).length() + 1;
            }
            count = chars;
            size = count;
        }

        int tagNumber = f.getTagNumber();
        stream.writeShort(tagNumber);
        stream.writeShort(type);
        stream.writeInt(count);

        // Write a dummy value to fill space
        stream.writeInt(0);
        stream.mark(); // Mark beginning of next field
        stream.skipBytes(-4);

        long pos;

        if (size > 4 || tag.isIFDPointer()) {
            // Ensure IFD or value is written on a word boundary
            nextSpace = (nextSpace + 3) & ~0x3;

            stream.writeInt((int)nextSpace);
            stream.seek(nextSpace);
            pos = nextSpace;

            if (tag.isIFDPointer() && f.hasDirectory()) {
                TIFFIFD subIFD = getDirectoryAsIFD(f.getDirectory());
                subIFD.writeToStream(stream);
                nextSpace = subIFD.lastPosition;
            } else {
                writeTIFFFieldToStream(f, stream);
                nextSpace = stream.getStreamPosition();
            }
        } else {
            pos = stream.getStreamPosition();
            writeTIFFFieldToStream(f, stream);
        }

        // If we are writing the data for the
        // StripByteCounts, TileByteCounts, StripOffsets,
        // TileOffsets, JPEGInterchangeFormat, or
        // JPEGInterchangeFormatLength fields, record the current stream
        // position for backpatching
        if (tagNumber ==
            BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH) {
            this.stripOrTileByteCountsPosition = pos;
        } else if (tagNumber ==
                   BaselineTIFFTagSet.TAG_STRIP_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_TILE_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT) {
            this.stripOrTileOffsetsPosition = pos;
        }

        stream.reset(); // Go to marked position of next field
    }

    this.lastPosition = nextSpace;
}
 
Example 20
Source File: SubImageOutputStream.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public SubImageOutputStream(ImageOutputStream out, ByteOrder bo,boolean forwardFlushAndClose) throws IOException {
    this(out, out.getStreamPosition(),bo,forwardFlushAndClose);
}