Java OutputStream Write serializeUUID(OutputStream out, UUID id)

Here you can find the source of serializeUUID(OutputStream out, UUID id)

Description

serialize UUID

License

Open Source License

Declaration

public static void serializeUUID(OutputStream out, UUID id) 

Method Source Code


//package com.java2s;
/* /*from   ww  w  .  j a  v  a 2s.c  o  m*/
 * This file is part of the HyperGraphDB source distribution. This is copyrighted 
 * software. For permitted uses, licensing options and redistribution, please see  
 * the LicensingInformation file at the root level of the distribution.  
 * 
 * Copyright (c) 2005-2010 Kobrix Software, Inc.  All rights reserved. 
 */

import java.io.IOException;

import java.io.OutputStream;
import java.util.UUID;

public class Main {
    public static void serializeUUID(OutputStream out, UUID id) {
        long msb = id.getMostSignificantBits();
        long lsb = id.getLeastSignificantBits();
        byte[] data = new byte[16];
        data[0] = (byte) ((msb >>> 56));
        data[1] = (byte) ((msb >>> 48));
        data[2] = (byte) ((msb >>> 40));
        data[3] = (byte) ((msb >>> 32));
        data[4] = (byte) ((msb >>> 24));
        data[5] = (byte) ((msb >>> 16));
        data[6] = (byte) ((msb >>> 8));
        data[7] = (byte) ((msb >>> 0));
        data[8] = (byte) ((lsb >>> 56));
        data[9] = (byte) ((lsb >>> 48));
        data[10] = (byte) ((lsb >>> 40));
        data[11] = (byte) ((lsb >>> 32));
        data[12] = (byte) ((lsb >>> 24));
        data[13] = (byte) ((lsb >>> 16));
        data[14] = (byte) ((lsb >>> 8));
        data[15] = (byte) ((lsb >>> 0));

        try {
            out.write(data);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Related

  1. serializeSpecial(OutputStream os, Serializable obj)
  2. serializeString(OutputStream out, String data)
  3. serializeString(String str, DataOutputStream dout)
  4. serializeTo(OutputStream outputStream, Object obj)
  5. serializeToOutputStream(final Serializable ser, final OutputStream os)
  6. writeStream(byte[] data, OutputStream os)
  7. writeStream(byte[] data, OutputStream out)
  8. writeStream(final OutputStream out, final String content, final boolean close)
  9. writeStream(InputStream _from, Writer _printTo)