Java OutputStream Write serializeString(OutputStream out, String data)

Here you can find the source of serializeString(OutputStream out, String data)

Description

serialize String

License

Open Source License

Declaration

public static void serializeString(OutputStream out, String data) 

Method Source Code


//package com.java2s;
/* /*from   w w w.  j  ava  2  s .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;

public class Main {
    public static void serializeString(OutputStream out, String data) {
        byte[] byteData = data.getBytes();

        serializeInt(out, byteData.length);
        try {
            out.write(byteData);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void serializeInt(OutputStream out, Integer data) {
        // assume not null
        try {
            int v = ((Integer) data).intValue();
            out.write((byte) ((v >>> 24) & 0xFF));
            out.write((byte) ((v >>> 16) & 0xFF));
            out.write((byte) ((v >>> 8) & 0xFF));
            out.write((byte) ((v >>> 0) & 0xFF));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Related

  1. serializeInt(OutputStream out, Integer data)
  2. serializeNull(DataOutputStream dout)
  3. serializeObject(OutputStream out, Object o)
  4. serializeShortLE(short value, OutputStream outStream)
  5. serializeSpecial(OutputStream os, Serializable obj)
  6. serializeString(String str, DataOutputStream dout)
  7. serializeTo(OutputStream outputStream, Object obj)
  8. serializeToOutputStream(final Serializable ser, final OutputStream os)
  9. serializeUUID(OutputStream out, UUID id)