List of usage examples for java.io DataInputStream readUTF
public final String readUTF() throws IOException
readUTF
method of DataInput
. From source file:EZShare.SubscribeCommandConnection.java
public static void establishPersistentConnection(Boolean secure, int port, String ip, int id, JSONObject unsubscribJsonObject, String commandname, String name, String owner, String description, String channel, String uri, List<String> tags, String ezserver, String secret, Boolean relay, String servers) throws URISyntaxException { //secure = false; try {//ww w . ja v a 2s . c o m System.out.print(port + ip); Socket socket = null; if (secure) { SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); socket = (SSLSocket) sslsocketfactory.createSocket(ip, port); } else { socket = new Socket(ip, port); } BufferedReader Reader = new BufferedReader(new InputStreamReader(System.in)); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); DataInputStream input = new DataInputStream(socket.getInputStream()); JSONObject command = new JSONObject(); Resource resource = new Resource(); command = resource.inputToJSON(commandname, id, name, owner, description, channel, uri, tags, ezserver, secret, relay, servers); output.writeUTF(command.toJSONString()); Client.debug("SEND", command.toJSONString()); //output.writeUTF(command.toJSONString()); new Thread(new Runnable() { @Override public void run() { String string = null; try { while (true/*(string = input.readUTF()) != null*/) { String serverResponse = input.readUTF(); JSONParser parser = new JSONParser(); JSONObject response = (JSONObject) parser.parse(serverResponse); Client.debug("RECEIVE", response.toJSONString()); //System.out.println(serverResponse); // if((string = Reader.readLine()) != null){ // if(onKeyPressed(output,string,unsubscribJsonObject)) break; // } if (flag == 1) { break; } } } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); new Thread(new Runnable() { @Override public void run() { String string = null; try { while ((string = Reader.readLine()) != null) { flag = 1; if (onKeyPressed(output, string, unsubscribJsonObject)) break; } } catch (IOException e) { e.printStackTrace(); } } }).start(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public void run() { while (true) { try {//from w ww . j a va 2s . c o m System.out.println("Waiting for client on port " + serverSocket.getLocalPort() + "..."); Socket server = serverSocket.accept(); System.out.println("Just connected to " + server.getRemoteSocketAddress()); DataInputStream in = new DataInputStream(server.getInputStream()); System.out.println(in.readUTF()); DataOutputStream out = new DataOutputStream(server.getOutputStream()); out.writeUTF("Thank you for connecting to " + server.getLocalSocketAddress() + "\nGoodbye!"); server.close(); } catch (SocketTimeoutException s) { System.out.println("Socket timed out!"); break; } catch (IOException e) { e.printStackTrace(); break; } } }
From source file:org.apache.cassandra.db.RangeCommand.java
public RangeCommand deserialize(DataInputStream dis) throws IOException { return new RangeCommand(dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readInt()); }
From source file:net.brtly.monkeyboard.plugin.core.panel.PluginDockableLayout.java
@Override public void readStream(DataInputStream in) throws IOException { _id = in.readUTF(); // get the plugin ID int bs = in.readInt(); // get the size, in bytes, of the Bundle byte[] b = new byte[bs]; // read the Bundle in.read(b);// w w w . j a v a 2 s. com }
From source file:org.apache.cassandra.db.migration.SerializationsTest.java
@Test public void testRead() throws IOException, ConfigurationException { if (AbstractSerializationsTester.EXECUTE_WRITES) testWrite();//from w w w . ja v a 2s . co m for (int i = 0; i < ksCount; i++) { String tableName = "Keyspace" + (i + 1); DataInputStream in = getInput("db.migration." + tableName + ".bin"); byte[] raw = Base64.decodeBase64(in.readUTF().getBytes()); org.apache.cassandra.db.migration.avro.Migration obj = new org.apache.cassandra.db.migration.avro.Migration(); SerDeUtils.deserializeWithSchema(ByteBuffer.wrap(raw), obj); in.close(); } }
From source file:nfinity.FindPeer.java
public Boolean ConnectPeerListener(String ip) { try {/* w w w. j a v a 2s.c o m*/ //Soocket = socket = new Socket(ip, 1000); Socket socket = new Socket(); socket.connect(new InetSocketAddress(ip, 1000), 1000); DataInputStream input = new DataInputStream(socket.getInputStream()); String data = input.readUTF(); System.out.println(data); String rspdata[] = data.split(" "); if (!rspdata[2].equals("")) { RemotePeerID = rspdata[2]; return true; } socket.close(); } catch (IOException ex) { System.out.println("Connection failed " + ex.getMessage()); } return false; }
From source file:com.facebook.infrastructure.db.ReadResponse.java
public ReadResponse deserialize(DataInputStream dis) throws IOException { String table = dis.readUTF(); int digestSize = dis.readInt(); byte[] digest = new byte[digestSize]; dis.read(digest, 0, digestSize);/*from w ww .j a v a 2 s . com*/ boolean isDigest = dis.readBoolean(); Row row = null; if (!isDigest) { row = Row.serializer().deserialize(dis); } ReadResponse rmsg = null; if (isDigest) { rmsg = new ReadResponse(table, digest); } else { rmsg = new ReadResponse(table, row); } rmsg.setIsDigestQuery(isDigest); return rmsg; }
From source file:org.apache.cassandra.db.SliceByNamesReadCommand.java
@Override public ReadCommand deserialize(DataInputStream dis) throws IOException { boolean isDigest = dis.readBoolean(); String table = dis.readUTF(); String key = dis.readUTF();/*from w w w . j a v a2 s . co m*/ QueryPath columnParent = QueryPath.deserialize(dis); int size = dis.readInt(); List<byte[]> columns = new ArrayList<byte[]>(); for (int i = 0; i < size; ++i) { columns.add(ColumnSerializer.readName(dis)); } SliceByNamesReadCommand rm = new SliceByNamesReadCommand(table, key, columnParent, columns); rm.setDigestQuery(isDigest); return rm; }
From source file:Main.java
public String downloadWWWPage(URL pageURL) throws Exception { String host, file;//from w ww .j a v a 2s. c o m host = pageURL.getHost(); file = pageURL.getFile(); InputStream pageStream = getWWWPageStream(host, file); if (pageStream == null) { return ""; } DataInputStream in = new DataInputStream(pageStream); StringBuffer pageBuffer = new StringBuffer(); String line; while ((line = in.readUTF()) != null) { pageBuffer.append(line); } in.close(); return pageBuffer.toString(); }
From source file:com.yattatech.io.ShalomFileReader.java
public Seminary read(String path) { Seminary seminary = null;/*from ww w .ja v a 2s .co m*/ DataInputStream input = null; try { input = new DataInputStream(new FileInputStream(path)); long checksum = input.readLong(); input.readUTF(); // skip /n character String json = input.readUTF(); long checksum2 = ChecksumCalculator.calculateChecksum(json); if (checksum == checksum2) { seminary = new Gson().fromJson(json, Seminary.class); } } catch (IOException ioe) { LOGGER.log(Level.SEVERE, ioe.getMessage()); } finally { IOUtils.closeQuietly(input); return seminary; } }