code: public static BufferedImage read (ByteBuffer byteBuffer)
          throws IOException
      {
          // read in our integer fields
          IntBuffer ibuf = byteBuffer.asIntBuffer();
          int width = ibuf.get();
          int height = ibuf.get();
          /* int tpixel = */ ibuf.get();
          int msize = ibuf.get();
  
          if (width > Short.MAX_VALUE || width < 0 || height > Short.MAX_VALUE || height < 0) {
              throw new IOException("Bogus image size " + width + "x" + height);
          }
  
          IndexColorModel cmodel;
          synchronized (_origin) { // any old object will do
              // make sure our colormap array is big enough
              if  (_cmap == null || _cmap.length < msize) {
                  _cmap = new int[msize];
              }
              // read in the data and create our colormap
              ibuf.get(_cmap, 0, msize);
              cmodel = new IndexColorModel(
                  8, msize, _cmap, 0, DataBuffer.TYPE_BYTE, null);
          }
  
          // advance the byte buffer accordingly
          byteBuffer.position(ibuf.position() * 4);
  
          // read in the image data itself
          byte[] data = new byte[width*height];
          byteBuffer.get(data);
  
          // create the image from our component parts
          DataBuffer dbuf = new DataBufferByte(data, data.length, 0);
          int[] offsets = new int[] { 0 };
          PixelInterleavedSampleModel smodel =
              new PixelInterleavedSampleModel(
                  DataBuffer.TYPE_BYTE, width, height, 1, width, offsets);
          WritableRaster raster = WritableRaster.createWritableRaster(smodel, dbuf, _origin);
          return new BufferedImage(cmodel, raster, false, null);
      }
docs: Reads an image from the supplied byte buffer (which must return the image format previously
  written via a call to {@link #write}).
  
  @exception IOException thrown if an error occurs reading from the file.