Here you can find the source of serializeString(OutputStream out, String data)
public static void serializeString(OutputStream out, String data)
//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(); } } }