Here you can find the source of stringsToBinary(final String strings[])
Parameter | Description |
---|---|
string | incoming String to convert |
public static byte[] stringsToBinary(final String strings[])
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; public class Main { public static final Charset GEOWAVE_CHAR_SET = Charset.forName("ISO-8859-1"); /**//from w w w .j a v a 2s .c om * Utility to convert a String to bytes * * @param string * incoming String to convert * @return a byte array */ public static byte[] stringsToBinary(final String strings[]) { int len = 4; final List<byte[]> strsBytes = new ArrayList<byte[]>(); for (final String str : strings) { final byte[] strByte = str.getBytes(GEOWAVE_CHAR_SET); strsBytes.add(strByte); len += (strByte.length + 4); } final ByteBuffer buf = ByteBuffer.allocate(len); buf.putInt(strings.length); for (final byte[] str : strsBytes) { buf.putInt(str.length); buf.put(str); } return buf.array(); } }