List of usage examples for java.io DataOutputStream writeUTF
public final void writeUTF(String str) throws IOException
From source file:webcamstream.ClientConnection.java
public static void main(String... a) throws IOException { Socket cs = new Socket("localhost", SERVER_PORT); System.out.println("socket created"); DataInputStream ci = new DataInputStream(cs.getInputStream()); DataOutputStream co = new DataOutputStream(cs.getOutputStream()); //sending negotiaiton to the server Message m = new Message(FieldValues.STARTSTREAM.getValue(), FieldValues.FORMAT.getValue(), width, height); co.writeUTF(m.toJSONString()); byte[] base64 = new byte[width * height * 3]; while (true) { byte[] msgBytes = new byte[base64.length + 2048]; ci.read(msgBytes);/*w w w.j av a2 s. co m*/ System.out.println(new String(msgBytes)); Message sm = Message.parseJSONString(new String(msgBytes).trim()); //decode an image byte[] compressedImage = Base64.decodeBase64(base64); //decompressing an image byte[] decompressedImage = Compressor.decompress(compressedImage); System.out.println(decompressedImage.length); } }
From source file:Main.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); MessageDigest md = MessageDigest.getInstance("MD5"); SomeObject testObject = new SomeObject(); dos.writeInt(testObject.count);// w w w.ja v a 2 s . c o m dos.writeLong(testObject.product); dos.writeDouble(testObject.stdDev); dos.writeUTF(testObject.name); dos.writeChar(testObject.delimiter); dos.flush(); byte[] hashBytes = md.digest(baos.toByteArray()); BigInteger testObjectHash = new BigInteger(hashBytes); System.out.println("Hash " + testObjectHash); dos.close(); }
From source file:delete_tcp.java
public static void main(String ar[]) throws IOException { ServerSocket ss = new ServerSocket(9999); Socket s = ss.accept();// w w w. ja va 2 s. com 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:com.splout.db.dnode.TCPStreamer.java
/** * This main method can be used for testing the TCP interface directly to a * local DNode. Will ask for protocol input from Stdin and print output to * Stdout//from w w w. j a va2s.c o m */ public static void main(String[] args) throws UnknownHostException, IOException, SerializationException { SploutConfiguration config = SploutConfiguration.get(); Socket clientSocket = new Socket("localhost", config.getInt(DNodeProperties.STREAMING_PORT)); DataInputStream inFromServer = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())); DataOutputStream outToServer = new DataOutputStream( new BufferedOutputStream(clientSocket.getOutputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter tablespace: "); String tablespace = reader.readLine(); System.out.println("Enter version number: "); long versionNumber = Long.parseLong(reader.readLine()); System.out.println("Enter partition: "); int partition = Integer.parseInt(reader.readLine()); System.out.println("Enter query: "); String query = reader.readLine(); outToServer.writeUTF(tablespace); outToServer.writeLong(versionNumber); outToServer.writeInt(partition); outToServer.writeUTF(query); outToServer.flush(); byte[] buffer = new byte[0]; boolean read; do { read = false; int nBytes = inFromServer.readInt(); if (nBytes > 0) { buffer = new byte[nBytes]; int inRead = inFromServer.read(buffer); if (inRead > 0) { Object[] res = ResultSerializer.deserialize(ByteBuffer.wrap(buffer), Object[].class); read = true; System.out.println(Arrays.toString(res)); } } } while (read); clientSocket.close(); }
From source file:cacheservice.CacheServer.java
/** * @param args the command line arguments *///from w w w . ja v a 2 s . com 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:WriteBinaryFile.java
private static void writeMovie(Product m, DataOutputStream out) throws Exception { out.writeUTF(m.title); out.writeInt(m.year);//from w w w . ja va 2 s. co m out.writeDouble(m.price); }
From source file:Main.java
public static void writeString(DataOutputStream out, String val) throws IOException { out.writeUTF(val); //we could easily come up with more efficient default encoding for string }
From source file:Main.java
public static void writeContatctInfo(String accountId, Vector contactInfo, File contactInfoFile) throws IOException { contactInfoFile.getParentFile().mkdirs(); FileOutputStream contactFileOutputStream = new FileOutputStream(contactInfoFile); DataOutputStream out = new DataOutputStream(contactFileOutputStream); out.writeUTF((String) contactInfo.get(0)); out.writeInt(((Integer) (contactInfo.get(1))).intValue()); for (int i = 2; i < contactInfo.size(); ++i) { out.writeUTF((String) contactInfo.get(i)); }/*w ww . jav a 2 s .c om*/ out.close(); }
From source file:org.apache.reef.io.data.loading.impl.DistributedDataSetPartitionSerializer.java
public static String serialize(final DistributedDataSetPartition partition) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final DataOutputStream daos = new DataOutputStream(baos); daos.writeUTF(partition.getPath()); daos.writeUTF(partition.getLocation()); daos.writeInt(partition.getDesiredSplits()); return Base64.encodeBase64String(baos.toByteArray()); } catch (final IOException e) { throw new RuntimeException("Unable to serialize distributed data partition", e); }/*from ww w . j a va 2 s . c o m*/ }
From source file:Main.java
private static byte[] stringToBytes(String string) { if (string == null) { return null; }//from www.j a v a 2s . com byte[] buffer = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeUTF(string); buffer = baos.toByteArray(); } catch (IOException ex) { } finally { try { baos.close(); dos.close(); } catch (IOException ex1) { } baos = null; dos = null; } return buffer; }