List of usage examples for java.lang String String
public String(StringBuilder builder)
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new BouncyCastleProvider()); byte[] input = "www.java2s.com".getBytes(); System.out.println("input : " + new String(input)); MessageDigest hash = MessageDigest.getInstance("SHA1"); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input); DigestInputStream digestInputStream = new DigestInputStream(byteArrayInputStream, hash); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int ch;//from w w w . ja v a 2s . c o m while ((ch = digestInputStream.read()) >= 0) { byteArrayOutputStream.write(ch); } byte[] newInput = byteArrayOutputStream.toByteArray(); System.out.println("in digest : " + new String(digestInputStream.getMessageDigest().digest())); byteArrayOutputStream = new ByteArrayOutputStream(); DigestOutputStream digestOutputStream = new DigestOutputStream(byteArrayOutputStream, hash); digestOutputStream.write(newInput); digestOutputStream.close(); System.out.println("out digest: " + new String(digestOutputStream.getMessageDigest().digest())); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getOracleConnection(); String[] columnNames = { "id", "name", "content", "date_created" }; Object[] inputValues = new Object[columnNames.length]; inputValues[0] = new java.math.BigDecimal(100); inputValues[1] = new String("String Value"); inputValues[2] = new String("This is my resume."); inputValues[3] = new Timestamp((new java.util.Date()).getTime()); String insert = "insert into resume (id, name, content, date_created ) values(?, ?, ?, ?)"; PreparedStatement pstmt = conn.prepareStatement(insert); pstmt.setObject(1, inputValues[0]);//from w w w. ja va 2 s .c o m pstmt.setObject(2, inputValues[1]); pstmt.setObject(3, inputValues[2]); pstmt.setObject(4, inputValues[3]); pstmt.executeUpdate(); String query = "select id, name, content, date_created from resume where id=?"; PreparedStatement pstmt2 = conn.prepareStatement(query); pstmt2.setObject(1, inputValues[0]); ResultSet rs = pstmt2.executeQuery(); Object[] outputValues = new Object[columnNames.length]; if (rs.next()) { for (int i = 0; i < columnNames.length; i++) { outputValues[i] = rs.getObject(i + 1); } } System.out.println("id=" + ((java.math.BigDecimal) outputValues[0]).toString()); System.out.println("name=" + ((String) outputValues[1])); System.out.println("content=" + ((Clob) outputValues[2])); System.out.println("date_created=" + ((java.sql.Date) outputValues[3]).toString()); rs.close(); pstmt.close(); pstmt2.close(); conn.close(); }
From source file:Main.java
public static void main(String args[]) { try {/*from w w w .ja va 2s.co m*/ int port = 80; DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length, InetAddress.getByName("google.com"), 8080); 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 w w w. j a va 2s . com*/ int port = 80; DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, 0, buffer.length, InetAddress.getByName("google.com"), 8080); ds.receive(dp); String str = new String(dp.getData()); System.out.println(str); } } catch (Exception e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) { String phrase = new String("www.java2s.com\n"); File aFile = new File("test.txt"); FileOutputStream outputFile = null; try {/* www. ja va 2s . c o m*/ outputFile = new FileOutputStream(aFile, true); System.out.println("File stream created successfully."); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } FileChannel outChannel = outputFile.getChannel(); ByteBuffer buf = ByteBuffer.allocate(1024); System.out.println("New buffer: position = " + buf.position() + "\tLimit = " + buf.limit() + "\tcapacity = " + buf.capacity()); // Load the data into the buffer for (char ch : phrase.toCharArray()) { buf.putChar(ch); } System.out.println("Buffer after loading: position = " + buf.position() + "\tLimit = " + buf.limit() + "\tcapacity = " + buf.capacity()); buf.flip(); System.out.println("Buffer after flip: position = " + buf.position() + "\tLimit = " + buf.limit() + "\tcapacity = " + buf.capacity()); try { outChannel.write(buf); outputFile.close(); System.out.println("Buffer contents written to file."); } catch (IOException e) { e.printStackTrace(System.err); } }
From source file:Main.java
public static void main(String[] args) { try {//from w w w.j a va 2s. c o m byte[] buffer = new byte[1024]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); DatagramSocket socket = new DatagramSocket(5002); System.out.println("Waiting for a packet..."); socket.receive(packet); System.out.println("Just received packet from " + packet.getSocketAddress()); buffer = packet.getData(); System.out.println(new String(buffer)); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {//from w w w . ja v a 2 s .c om int port = 80; DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length, InetSocketAddress.createUnresolved("google.com", 8080)); 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 {// www. ja va2 s. c o m String s = "Hello world from java2s.com"; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF(s); // set the file pointer at 0 position raf.seek(0); // create an array equal to the length of raf byte[] arr = new byte[10]; // read the file raf.readFully(arr, 3, 7); // create a new string based on arr String s2 = new String(arr); // print it System.out.println(s2); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { PdfReader reader = new PdfReader("2.pdf"); Map info = reader.getInfo();/*from w ww .ja v a 2 s . c om*/ for (Iterator i = info.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); String value = (String) info.get(key); System.out.println(key + ": " + value); } if (reader.getMetadata() == null) { System.out.println("No XML Metadata."); } else { System.out.println("XML Metadata: " + new String(reader.getMetadata())); } }
From source file:GetDate.java
public static void main(String args[]) throws Exception { byte msg[] = new byte[256]; DatagramSocket dgSocket = new DatagramSocket(); InetAddress destination = InetAddress.getByName("web.mit.edu"); DatagramPacket datagram = new DatagramPacket(msg, msg.length, destination, PortDayTime); dgSocket.send(datagram);/* w w w. j a v a2 s . c o m*/ datagram = new DatagramPacket(msg, msg.length); dgSocket.receive(datagram); String received = new String(datagram.getData()); System.out.println("The time in Cambridge is now: " + received); dgSocket.close(); }