List of usage examples for java.lang String String
public String(StringBuilder builder)
From source file:Main.java
public static void main(String[] args) throws NoSuchAlgorithmException { int numBytes = (new Integer("1111")).intValue(); SecureRandom srand = SecureRandom.getInstance("SHA1PRNG"); srand.setSeed(new byte[] { 1, 2, 3, 4 }); byte[] bytes = new byte[numBytes]; srand.nextBytes(bytes);/*from ww w . j a v a 2s. c o m*/ System.out.println(new String(bytes)); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String alg = "HmacMD5"; Mac mac = Mac.getInstance(alg); KeyGenerator kg = KeyGenerator.getInstance(alg); SecretKey key = kg.generateKey(); mac.init(key);//from w ww . j a va2 s .c om mac.update("test".getBytes()); byte[] b = mac.doFinal(); System.out.println(new String(b)); }
From source file:Main.java
public static void main(String args[]) throws IOException { FileInputStream fis = new FileInputStream("FileChannelExample.java"); FileChannel fc = fis.getChannel(); ByteBuffer bb = ByteBuffer.allocate((int) fc.size()); fc.read(bb);/*from w ww.java 2 s . c o m*/ bb.flip(); String fileContent = new String(bb.array()); fc.close(); fc = null; System.out.println("fileContent = " + fileContent); }
From source file:DatagramReceiver.java
public static void main(String args[]) throws Exception { int port = Integer.parseInt(args[0]); DatagramSocket ds = new DatagramSocket(port); byte buffer[] = new byte[BUFSIZE]; while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); ds.receive(dp);/* w w w .j ava2 s. c om*/ System.out.println(new String(dp.getData())); } }
From source file:Collector.java
public static void main(String args[]) throws Exception { int port = Integer.parseInt(args[0]); DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); ds.receive(dp);//from w ww .ja v a 2 s . c o m System.out.println(new String(dp.getData())); } }
From source file:PacketReceiver.java
public static void main(String[] args) throws Exception { byte[] buffer = new byte[1024]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); DatagramSocket socket = new DatagramSocket(5002); socket.receive(packet);//w w w. j a va 2s . c o m System.out.println(packet.getSocketAddress()); buffer = packet.getData(); System.out.println(new String(buffer)); }
From source file:Main.java
public static void main(String args[]) { try {// w ww. j a va 2s.c om int port = 80; DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); ds.receive(dp); String str = new String(dp.getData()); System.out.println(str); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {// w w w .j a v a 2 s.c o m int port = 80; DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); ds.receive(dp); String str = new String(dp.getData()); System.out.println(str); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {//from ww w .ja v a 2s .co m int port = 80; DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, 0, buffer.length); ds.receive(dp); String str = new String(dp.getData()); System.out.println(str); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Console console = System.console(); if (console != null) { console.printf("Console is available.%n"); } else {/* w w w. j ava2 s .c o m*/ System.out.println("Console is not available.%n"); return; // A console is not available } String userName = console.readLine("User Name: "); char[] passChars = console.readPassword("Password: "); String passString = new String(passChars); if (passString.equals("letmein")) { console.printf("Hello %s", userName); } else { console.printf("Invalid password"); } }