List of usage examples for java.lang String getBytes
public byte[] getBytes()
From source file:Main.java
public static void main(String[] args) { String stringToConvert = "this is a test"; byte[] theByteArray = stringToConvert.getBytes(); System.out.println(theByteArray.length); }
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 ww .jav a 2 s . c o m*/ int c; while ((c = in.read()) != -1) { System.out.print((char) c); } s.setTrafficClass(1); System.out.println(s.getTrafficClass()); 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);/* w w w .ja va2 s . c o m*/ int c; while ((c = in.read()) != -1) { System.out.print((char) c); } s.setOOBInline(true); System.out.println(s.getOOBInline()); 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 ww .j av a 2 s . co m*/ int c; while ((c = in.read()) != -1) { System.out.print((char) c); } s.shutdownInput(); s.shutdownOutput(); 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);// ww w. j a v a 2s .c o m int c; while ((c = in.read()) != -1) { System.out.print((char) c); } SocketChannel socketChannel = s.getChannel(); System.out.println(socketChannel.getLocalAddress()); s.close(); }
From source file:Main.java
public static void main(String args[]) throws IOException { DatagramSocket socket = new DatagramSocket(DAYTIME_PORT); while (true) { byte buffer[] = new byte[256]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); socket.receive(packet);//from w ww . j av a2 s .co m String date = new Date().toString(); buffer = date.getBytes(); // Get response address/port for client from packet InetAddress address = packet.getAddress(); int port = packet.getPort(); packet = new DatagramPacket(buffer, buffer.length, address, port); socket.send(packet); } }
From source file:Main.java
public static void main(String[] args) { String hello = "aaaaaaaa"; byte[] decoded = Base64.decodeBase64(hello.getBytes()); System.out.println(Arrays.toString(decoded)); String decodedString = new String(decoded); System.out.println(hello + " = " + decodedString); }
From source file:MainClass.java
public static void main(String[] args) { try {/*from w w w .j ava2s . com*/ String data = "data in UDP"; byte[] buffer = data.getBytes(); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, new InetSocketAddress("localhost", 5002)); DatagramSocket socket = new DatagramSocket(5003); System.out.println("Sending a packet..."); socket.send(packet); } catch (IOException e) { e.printStackTrace(); } }
From source file:Base64Encode.java
public static void main(String[] args) { String hello = "Hello World"; byte[] encoded = Base64.encodeBase64(hello.getBytes()); System.out.println(Arrays.toString(encoded)); String encodedString = new String(encoded); System.out.println(hello + " = " + encodedString); }
From source file:MainClass.java
public static void main(String[] arg) { String text = "To be or not to be"; // Define a string byte[] textArray = text.getBytes(); for (byte b : textArray) { System.out.println(b);/*from w w w . ja v a2 s. c om*/ } }