Java ByteBuffer Write writeFakeImageData(ByteBuffer out, int lzwMinCodeSize)

Here you can find the source of writeFakeImageData(ByteBuffer out, int lzwMinCodeSize)

Description

write Fake Image Data

License

Open Source License

Declaration

public static void writeFakeImageData(ByteBuffer out, int lzwMinCodeSize) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static void writeFakeImageData(ByteBuffer out, int lzwMinCodeSize) {
        // 1 for lzwMinCodeSize, 1 for length, 1 for min content, 1 for block terminator.
        verifyRemaining(out, 4);// w ww . j  a va2s .  c  o m
        verifyShortValues(lzwMinCodeSize);

        out.put((byte) lzwMinCodeSize);
        // Block length.
        out.put((byte) 0x01);
        // Block content.
        out.put((byte) 0x01);
        // End of block.
        out.put((byte) 0x00);
    }

    private static void verifyRemaining(ByteBuffer buffer, int expected) {
        if (buffer.remaining() < expected) {
            throw new IllegalArgumentException("Must have at least "
                    + expected + " bytes to write");
        }
    }

    private static void verifyShortValues(int... shortValues) {
        for (int dimen : shortValues) {
            if (dimen > Short.MAX_VALUE || dimen < 0) {
                throw new IllegalArgumentException(
                        "Must pass in non-negative short dimensions, not: "
                                + dimen);
            }
        }
    }
}

Related

  1. writeCInt(ByteBuffer buffer, int anInt)
  2. writeColorTable(ByteBuffer out, int numColors)
  3. writeDouble(ByteBuffer buffer, double d)
  4. writeDouble(double v, ByteBuffer buffer)
  5. writeEmpty(final ByteBuffer buffer, final int type)
  6. writeFFloat(ByteBuffer buffer, float value)
  7. writeFile(ByteBuffer data, File destination)
  8. writeFile(File file, ByteBuffer bb)
  9. writeFile(File file, ByteBuffer buffer)