convert To Byte Array Input Stream - Java java.lang

Java examples for java.lang:byte Array Convert

Description

convert To Byte Array Input Stream

Demo Code


//package com.java2s;
import java.io.ByteArrayInputStream;

public class Main {
    public static void main(String[] argv) throws Exception {
        String bytes = "java2s.com";
        System.out.println(convertToByteArrayInputStream(bytes));
    }/*from www  .  j  a va 2  s . com*/

    private static String ID = "235290996559476282L";

    public static ByteArrayInputStream convertToByteArrayInputStream(
            String bytes) {
        return new ByteArrayInputStream(convertToBytes(bytes));
    }

    public static byte[] convertToBytes(String bytesStr) {
        String[] bytes = bytesStr.substring(ID.length() + 1).split(",");
        byte[] result = new byte[bytes.length];
        for (int i = 0, len = result.length; i < len; i++) {
            result[i] = Byte.parseByte(bytes[i]);
        }
        return result;
    }
}

Related Tutorials