Here you can find the source of putOrCopyString(String fromString, byte[] toBytes)
public static byte[] putOrCopyString(String fromString, byte[] toBytes)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; public class Main { public static final String BYTE_CHARSET = "UTF-8"; public static byte[] putOrCopyString(String fromString, byte[] toBytes) { byte[] fromBytes; try {//from w w w .j av a 2s . c o m fromBytes = fromString.getBytes(BYTE_CHARSET); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } if (toBytes.length == fromBytes.length) { System.arraycopy(fromBytes, 0, toBytes, 0, fromBytes.length); } else { toBytes = fromBytes; } return fromBytes; } }