Example usage for java.io ByteArrayInputStream ByteArrayInputStream

List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream

Introduction

In this page you can find the example usage for java.io ByteArrayInputStream ByteArrayInputStream.

Prototype

public ByteArrayInputStream(byte buf[]) 

Source Link

Document

Creates a ByteArrayInputStream so that it uses buf as its buffer array.

Usage

From source file:Main.java

License:asdf

public static void main(String[] argv) throws Exception {

    byte[] bytes = "asdf".getBytes("UTF8");
    new ByteArrayInputStream(bytes);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    DataInputStream in3 = new DataInputStream(new ByteArrayInputStream("a dbcde".getBytes()));
    System.out.print((char) in3.readByte());
    in3.close();//  w  w w  .  j a  v a 2s  .  co  m
}

From source file:Main.java

public static void main(String[] args) {
    String str = "java2s.com";
    ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
    System.setIn(bais);//from  ww w  .java  2 s. c  o m

    Scanner scanner = new Scanner(System.in);
    String input = scanner.next();
    System.out.println(input);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String text = "Converting String to InputStream Example";
    InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte[] buf = { 65, 66, 67, 68, 69 };

    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    bais.close();/*from w  w  w  .j a  va  2  s.c o m*/

    int count = bais.available();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    byte[] buf = { 65, 66, 67, 68, 69 };

    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    int count = 0;

    while ((count = bais.available()) > 0) {
        char c = (char) bais.read();
        System.out.print("available byte(s) : " + count);
        System.out.println(c);//  w  w  w. j  av a  2  s.co m
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte[] buf = { 65, 66, 67, 68, 69 };

    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    int b = 0;// ww  w.j  a v a  2  s. c o m
    while ((b = bais.read()) != -1) {
        char c = (char) b;
        System.out.println("byte :" + b + "; char : " + c);
    }
    System.out.print(bais.read() + " Reached the end");
}

From source file:Main.java

public static void main(String[] args) {
    byte[] arrByte = new byte[1024];
    byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' };

    InputStream is = new ByteArrayInputStream(byteArray);
    PushbackInputStream pis = new PushbackInputStream(is);

    System.out.println(pis.markSupported());

}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte[] buf = { 65, 66, 67, 68, 69 };

    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    byte[] b = new byte[4];
    int num = bais.read(b, 2, 2);

    System.out.println("Bytes read: " + num);

    for (byte s : b) {
        char c = (char) s;
        System.out.println(s);/*  w ww.jav a  2  s . c o  m*/
        if (s == 0) {
            System.out.println(": Null");
        } else {
            System.out.println(": " + c);
        }
    }

}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    String tmp = "abc";
    byte b[] = tmp.getBytes();
    ByteArrayInputStream in = new ByteArrayInputStream(b);

    for (int i = 0; i < 2; i++) {
        int c;//from   w  w  w .j a va 2s. c  o  m
        while ((c = in.read()) != -1) {
            if (i == 0) {
                System.out.print((char) c);
            } else {
                System.out.print(Character.toUpperCase((char) c));
            }
        }
        System.out.println();
        in.reset();
    }
}