List of usage examples for java.io DataInputStream readUTF
public final String readUTF() throws IOException
readUTF
method of DataInput
. From source file:Main.java
public static void main(String[] argv) throws Exception { Socket t = new Socket("127.0.0.1", 7); DataInputStream dis = new DataInputStream(t.getInputStream()); PrintStream ps = new PrintStream(t.getOutputStream()); ps.println("Hello"); String str = dis.readUTF(); if (str.equals("Hello")) System.out.println("Alive!"); else/* www.ja va2 s .c o m*/ System.out.println("Dead"); t.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Data.txt"))); out2.writeDouble(3.14159);/*from w w w . jav a 2s .co m*/ out2.writeUTF("Square root of 2"); out2.close(); DataInputStream in5 = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt"))); System.out.println(in5.readDouble()); System.out.println(in5.readUTF()); }
From source file:delete_tcp.java
public static void main(String ar[]) throws IOException { ServerSocket ss = new ServerSocket(9999); Socket s = ss.accept();/* ww w .j a va 2 s .c om*/ DataInputStream in = new DataInputStream(s.getInputStream()); DataOutputStream out = new DataOutputStream(s.getOutputStream()); String id = in.readUTF(); ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); EmployeeJDBCTemplate employeeJDBCTemplate = (EmployeeJDBCTemplate) context.getBean("employeeJDBCTemplate"); System.out.println("Deleting Records..."); employeeJDBCTemplate.delete(Integer.parseInt(id)); out.writeUTF("Success"); s.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String host = "host"; int port = 25; String from = "from@from.net"; String toAddr = "to@to.net"; Socket servSocket = new Socket(host, port); DataOutputStream os = new DataOutputStream(servSocket.getOutputStream()); DataInputStream is = new DataInputStream(servSocket.getInputStream()); if (servSocket != null && os != null && is != null) { os.writeBytes("HELO\r\n"); os.writeBytes("MAIL From:" + from + " \r\n"); os.writeBytes("RCPT To:" + toAddr + "\r\n"); os.writeBytes("DATA\r\n"); os.writeBytes("X-Mailer: Java\r\n"); os.writeBytes(//from w w w.jav a 2 s. com "DATE: " + DateFormat.getDateInstance(DateFormat.FULL, Locale.US).format(new Date()) + "\r\n"); os.writeBytes("From:" + from + "\r\n"); os.writeBytes("To:" + toAddr + "\r\n"); } os.writeBytes("Subject:\r\n"); os.writeBytes("body\r\n"); os.writeBytes("\r\n.\r\n"); os.writeBytes("QUIT\r\n"); String responseline; while ((responseline = is.readUTF()) != null) { if (responseline.indexOf("Ok") != -1) break; } }
From source file:cacheservice.CacheServer.java
/** * @param args the command line arguments *///from w ww .jav a 2 s .c o m public static void main(String[] args) { // COMUNICACIN CON EL CLIENTE ServerSocket serverSocket; Socket socketCliente; DataInputStream in; //Flujo de datos de entrada DataOutputStream out; //Flujo de datos de salida String mensaje; int laTengoenCache = 0; //COMUNICACIN CON EL INDEX ServerSocket serverSocketIndex; Socket socketIndex; DataOutputStream outIndex; ObjectInputStream inIndex; String mensajeIndex; try { serverSocket = new ServerSocket(4444); System.out.print("SERVIDOR CACHE ACTIVO a la espera de peticiones"); //MIENTRAS PERMANEZCA ACTIVO EL SERVIDOR CACHE ESPERAR? POR PETICIONES DE LOS CLIENTES while (true) { socketCliente = serverSocket.accept(); in = new DataInputStream(socketCliente.getInputStream()); //Entrada de los mensajes del cliente mensaje = in.readUTF(); //Leo el mensaje enviado por el cliente System.out.println("\nHe recibido del cliente: " + mensaje); //Muestro el mensaje recibido por el cliente //int particionBuscada = seleccionarParticion(mensaje, tamanoCache, numeroParticiones); //Busco la particin //double tamanoParticion = Math.ceil( (double)tamanoCache / (double)numeroParticiones); //Thread hilo = new Hilo(mensaje,particionBuscada,cache.GetTable(),(int) tamanoParticion); //hilo.start(); //RESPUESTA DEL SERVIDOR CACHE AL CLIENTE out = new DataOutputStream(socketCliente.getOutputStream()); String respuesta = "Respuesta para " + mensaje; if (laTengoenCache == 1) { out.writeUTF(respuesta); System.out.println("\nTengo la respuesta. He respondido al cliente: " + respuesta); } else { out.writeUTF("miss"); out.close(); in.close(); socketCliente.close(); System.out.println("\nNo tengo la respuesta."); //LEER RESPUESTA DEL SERVIDOR INDEX serverSocketIndex = new ServerSocket(6666); socketIndex = serverSocketIndex.accept(); inIndex = new ObjectInputStream(socketIndex.getInputStream()); JSONObject mensajeRecibidoIndex = (JSONObject) inIndex.readObject(); System.out.println("He recibido del SERVIDOR INDEX: " + mensajeRecibidoIndex); //outIndex.close(); inIndex.close(); socketIndex.close(); } } } catch (Exception e) { System.out.print(e.getMessage()); } }
From source file:Main.java
public static String readString(DataInputStream in) throws IOException { return in.readUTF(); }
From source file:Main.java
public static String readNullableString(DataInputStream in) throws IOException { if (in.read() != 0) { return in.readUTF(); } else {//from w w w. ja v a 2 s . c om return null; } }
From source file:com.bigdata.dastor.db.filter.QueryPath.java
public static QueryPath deserialize(DataInputStream din) throws IOException { String cfName = din.readUTF(); byte[] scName = ColumnSerializer.readName(din); byte[] cName = ColumnSerializer.readName(din); return new QueryPath(cfName.isEmpty() ? null : cfName, scName.length == 0 ? null : scName, cName.length == 0 ? null : cName); }
From source file:ReadBinaryFile.java
private static Product readMovie(DataInputStream in) { String title = ""; int year = 0; double price = 0.0; try {/*from w w w. ja va 2 s. c o m*/ title = in.readUTF(); year = in.readInt(); price = in.readDouble(); } catch (EOFException e) { return null; } catch (IOException e) { System.out.println("I/O Error"); System.exit(0); } return new Product(title, year, price); }
From source file:Main.java
private static String bytesToString(byte[] bytes) { if (bytes == null) { return null; }/*from w w w. ja v a 2 s . c o m*/ ByteArrayInputStream bais = new ByteArrayInputStream(bytes); DataInputStream dis = new DataInputStream(bais); String res = ""; try { res = dis.readUTF(); } catch (IOException ex) { } finally { try { dis.close(); bais.close(); } catch (IOException ex1) { } dis = null; bais = null; } return res; }