Example #1
0
 public static byte[] getNBOPort(short p) {
   ByteBuffer buf = ByteBuffer.allocate(2);
   buf.putShort((short) p);
   buf.order(ByteOrder.BIG_ENDIAN);
   buf.rewind();
   byte[] rtn = new byte[2];
   buf.get(rtn);
   return rtn;
 }
Example #2
0
 public static byte[] getNBOHost(String h) {
   if (h.equals(PEER)) return null;
   byte hostBytes[] = h.getBytes();
   int len = Array.getLength(hostBytes);
   ByteBuffer buf = ByteBuffer.allocate(len);
   buf.put(hostBytes);
   buf.order(ByteOrder.BIG_ENDIAN);
   buf.rewind();
   return (buf.array());
 }
  private void readPalette() {
    RandomAccessFile rIn = null;
    ByteBuffer buf = null;
    int i;
    try {
      if (paletteFile != null) {
        // see if the file exists, if not, set it to the default palette.
        File file = new File(paletteFile);

        numPaletteEntries = (int) (file.length() / 4);

        buf = ByteBuffer.allocate(numPaletteEntries * 4);

        rIn = new RandomAccessFile(paletteFile, "r");

        FileChannel inChannel = rIn.getChannel();

        inChannel.position(0);
        inChannel.read(buf);

        // Check the byte order.
        buf.order(ByteOrder.LITTLE_ENDIAN);

        buf.rewind();
        IntBuffer ib = buf.asIntBuffer();
        paletteData = new int[numPaletteEntries];
        ib.get(paletteData);
        ib = null;
      }

    } catch (Exception e) {
      System.err.println("Caught exception: " + e.toString());
      System.err.println(e.getStackTrace());
    } finally {
      if (rIn != null) {
        try {
          rIn.close();
        } catch (Exception e) {
        }
      }
    }
  }