Example usage for java.lang String getBytes

List of usage examples for java.lang String getBytes

Introduction

In this page you can find the example usage for java.lang String getBytes.

Prototype

public byte[] getBytes() 

Source Link

Document

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    FileOutputStream fos = new FileOutputStream("test");
    MessageDigest md = MessageDigest.getInstance("SHA");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    String data = "thee";
    byte buf[] = data.getBytes();
    md.update(buf);/*www.j  a  v a  2  s .c o m*/
    oos.writeObject(data);
    oos.writeObject(md.digest());
}

From source file:Main.java

License:asdf

public static void main(String args[]) throws Exception {
    InetAddress ia = InetAddress.getByName(args[0]);
    int port = Integer.parseInt(args[1]);
    DatagramSocket ds = new DatagramSocket();
    while (true) {
        String s = "asdf";
        byte buffer[] = s.getBytes();
        DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, port);
        ds.send(dp);//from  ww w . j a va 2 s.  c  o  m
    }
}

From source file:Main.java

public static void main(String[] argv) {
    String str = "     j a v a 2 s.com    ";
    byte[] bytes = str.getBytes();
    System.out.println(Arrays.toString(bytes));
}

From source file:ByteArrayInputStreamDemo.java

public static void main(String args[]) throws IOException {
    String tmp = "abcdefghijklmnopqrstuvwxyz";
    byte b[] = tmp.getBytes();
    ByteArrayInputStream input1 = new ByteArrayInputStream(b);
    ByteArrayInputStream input2 = new ByteArrayInputStream(b, 0, 3);
}

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 ww.  java 2  s  .  co 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();
    }
}

From source file:Main.java

public static void main(String[] arg) {
    String text = "To be or not to be";
    byte[] textArray = text.getBytes();

    for (byte b : textArray) {
        System.out.println(b);//from   w ww  .  j  av  a  2 s.c  o  m
    }
}

From source file:Whois.java

License:asdf

public static void main(String args[]) throws Exception {
    int c;/*from  w w w. jav a2 s.c  om*/
    Socket s = new Socket("internic.net", 43);
    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();
    String str = "asdfasdfasdf\n";
    byte buf[] = str.getBytes();
    out.write(buf);
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }
    s.close();
}

From source file:Main.java

License:asdf

public static void main(String args[]) throws Exception {
    Socket s = new Socket("internic.net", 43);
    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();
    String str = "asdfasdfasdf\n";
    byte buf[] = str.getBytes();
    out.write(buf);//from  w w w .  j a va  2s .  c om
    int c;
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.setReceiveBufferSize(1);

    s.close();
}

From source file:Main.java

License:asdf

public static void main(String args[]) throws Exception {
    Socket s = new Socket("internic.net", 43);
    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();
    String str = "asdfasdfasdf\n";
    byte buf[] = str.getBytes();
    out.write(buf);//from  w w w  . j a  v a 2  s.  c om
    int c;
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.sendUrgentData(1);

    s.close();
}

From source file:Main.java

License:asdf

public static void main(String args[]) throws Exception {
    Socket s = new Socket("internic.net", 43);
    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();
    String str = "asdfasdfasdf\n";
    byte buf[] = str.getBytes();
    out.write(buf);/*from ww  w.  j  a v  a2  s .co m*/
    int c;
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

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

    s.close();
}