Example usage for java.io ByteArrayOutputStream write

List of usage examples for java.io ByteArrayOutputStream write

Introduction

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

Prototype

public synchronized void write(int b) 

Source Link

Document

Writes the specified byte to this ByteArrayOutputStream .

Usage

From source file:Main.java

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

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(bs);

    String str = baos.toString();

    System.out.println(str);// w  ww .  j  ava  2s.c  o  m

}

From source file:Main.java

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

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(bs);

    for (byte b : baos.toByteArray()) {
        baos.write(b);/*from  www .  j a  v  a2 s .co  m*/

        System.out.println(b);
    }

}

From source file:Main.java

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

    byte[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 };

    OutputStream os = new ByteArrayOutputStream();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(bs);

    baos.writeTo(os);//from w ww.  j a v  a  2s  . co m

    System.out.println(os.toString());

}

From source file:Main.java

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

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(bs);

    // converts buffers content using Cp1047 character set
    String str = baos.toString("Cp1047");
    System.out.println(str);/*from   w  ww .  ja  v  a 2 s.  c  om*/

    // converts buffers contents using UTF-8 character set
    str = baos.toString("UTF-8");
    System.out.println(str);

}

From source file:Main.java

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(75);

    String str = baos.toString();
    System.out.println("Before Resetting : " + str);

    baos.reset();//www. j  a  v  a2s  .  co  m

    baos.write(65);

    str = baos.toString();
    System.out.println("After Resetting : " + str);

}

From source file:Main.java

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

    byte[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 };

    OutputStream os = new ByteArrayOutputStream();

    ByteArrayOutputStream baos = new ByteArrayOutputStream(200);

    baos.write(bs);

    baos.writeTo(os);/*from www  . j  ava 2 s .co  m*/

    System.out.println(os.toString());

}

From source file:Main.java

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

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.close();/* w ww .ja  v  a2s .c o  m*/

    baos.write(buf);

    System.out.print(baos.toString());

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    KeyPair pair = generateRSAKeyPair();
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    bOut.write(generateV1Certificate(pair).getEncoded());
    bOut.close();//from w w w . j  av  a2s . co  m
    InputStream in = new ByteArrayInputStream(bOut.toByteArray());
    CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC");
    X509Certificate x509Cert = (X509Certificate) fact.generateCertificate(in);
    System.out.println("issuer: " + x509Cert.getIssuerX500Principal());
}

From source file:Main.java

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

    int size = 0;

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    for (byte b : bs) {
        baos.write(b);

        String str = baos.toString();
        size = baos.size();/*from w w  w.j  av  a 2  s .  c o  m*/

        System.out.print(size + ":");
        System.out.println(str);
    }

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // write byte array to the output stream
    baos.write(55);

    // converts the byte to the default charset value
    String str = baos.toString();

    // prints the string
    System.out.println(str);//  w w  w .  ja  va 2s  .com

}