Here you can find the source of writeColorTable(ByteBuffer out, int numColors)
public static void writeColorTable(ByteBuffer out, int numColors)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static void writeColorTable(ByteBuffer out, int numColors) { verifyRemaining(out, getColorTableLength(numColors)); for (int i = 0; i < numColors; i++) { out.put((byte) (0xFF0000 & i)); out.put((byte) (0x00FF00 & i)); out.put((byte) (0x0000FF & i)); }//from w ww . j a va 2 s . c om } private static void verifyRemaining(ByteBuffer buffer, int expected) { if (buffer.remaining() < expected) { throw new IllegalArgumentException("Must have at least " + expected + " bytes to write"); } } public static int getColorTableLength(int numColors) { return 3 * numColors; } }