List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:com.moz.fiji.hive.utils.ByteWritable.java
public static <T extends Writable> T asWritable(byte[] bytes, Class<T> clazz) throws IOException { T result = null;//from w w w. j a v a 2 s.co m DataInputStream dataIn = null; try { result = (T) WritableFactories.newInstance(clazz); ByteArrayInputStream in = new ByteArrayInputStream(bytes); dataIn = new DataInputStream(in); result.readFields(dataIn); } finally { IOUtils.closeQuietly(dataIn); } return result; }
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 {/*w w w . j av a2 s. 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:com.android.bandwidthtest.util.BandwidthTestUtil.java
/** * Parses the first line in a file if exists. * * @param file {@link File} the input/*from ww w . j ava 2 s . com*/ * @return the integer value of the first line of the file. */ public static int parseIntValueFromFile(File file) { int value = 0; if (file.exists()) { try { FileInputStream fstream = new FileInputStream(file); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine = br.readLine(); if (strLine != null) { value = Integer.parseInt(strLine); } // Close the input stream in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } return value; }
From source file:eu.learnpad.simulator.mon.utils.Manager.java
@SuppressWarnings("deprecation") public static Properties Read(String fileName) { Properties readedProps = new Properties(); File file = new File(fileName); FileInputStream fis = null;/*from ww w . jav a2 s . c o m*/ BufferedInputStream bis = null; DataInputStream dis = null; try { fis = new FileInputStream(file); // Here BufferedInputStream is added for fast reading. bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); // dis.available() returns 0 if the file does not have more lines. String property = ""; String key = ""; String value = ""; while (dis.available() != 0) { // this statement reads the line from the file and print it to // the console. property = dis.readLine().trim(); if (property.length() > 0) { key = property.substring(0, property.indexOf("=")); value = property.substring(property.indexOf("=") + 1, property.length()); readedProps.put(key.trim(), value.trim()); } } // dispose all the resources after using them. fis.close(); bis.close(); dis.close(); } catch (IOException e) { e.printStackTrace(); } return readedProps; }
From source file:com.vimukti.accounter.license.LicensePair.java
public LicensePair(String contactLicenseText) throws LicenseException { this.originalLicenseString = contactLicenseText; if (!new LicenseManager().canDecode(contactLicenseText)) { return;//from ww w . ja v a2s .co m } try { byte[] decodedBytes = Base64.decodeBase64(contactLicenseText.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes); DataInputStream dIn = new DataInputStream(in); int textLength = dIn.readInt(); this.licenseText = new byte[textLength]; dIn.read(licenseText); this.hash = new byte[dIn.available()]; dIn.read(hash); } catch (IOException e) { throw new LicenseException(e); } }
From source file:MainClass.java
public NumberConsumer(InputStream in) { theInput = new DataInputStream(in); }
From source file:nl.dreamkernel.s4.tweaker.util.RootProcess.java
public boolean init() { try {/* ww w . jav a 2 s.c o m*/ mProcess = Runtime.getRuntime().exec("su"); mOutputStream = new DataOutputStream(mProcess.getOutputStream()); mInputStream = new DataInputStream(mProcess.getInputStream()); if (write("su -v\n")) { String[] results = read(); for (String line : results) { if (line.length() > 0) { return true; } } } } catch (IOException e) { } return false; }
From source file:com.cloudera.impala.security.DelegationTokenIdentifier.java
/** * Deserializes the identifier from a byte array. *//* ww w . ja va2 s. co m*/ static DelegationTokenIdentifier deserialize(byte[] str) throws IOException { DelegationTokenIdentifier d = new DelegationTokenIdentifier(); d.readFields(new DataInputStream(new ByteArrayInputStream(str))); return d; }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.ClassVersionChecker.java
private void checkClassVersion(String filename) throws IOException { DataInputStream in = null;// w ww . ja v a2 s . c o m try { //noinspection IOResourceOpenedButNotSafelyClosed in = new DataInputStream(new FileInputStream(filename)); int magic = in.readInt(); // The first 4 bytes are a magic number, 0xCAFEBABe, to identify a valid class file // then the next 2 bytes identify the class format version (major and minor). // Possible major/minor value : // // major minor Java platform version // 45 3 1.0 // 45 3 1.1 // 46 0 1.2 // 47 0 1.3 // 48 0 1.4 // 49 0 1.5 // 50 0 1.6 if (magic != 0xcafebabe) LOGGER.info(filename + " is not a valid class!"); int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); LOGGER.info(filename + ": " + major + " . " + minor); } finally { IOUtils.closeQuietly(in); } }
From source file:org.jfree.chart.demo.SocketThread.java
@Override public void run() { // TODO Auto-generated method stub try {/*from w w w .j a v a 2s . c o m*/ ServerSocket ss = new ServerSocket(4444); Socket socket = null; while (Islive) { System.out.println("Started :) "); socket = ss.accept(); /* */ System.out.println("Got a client :) "); InputStream sin = socket.getInputStream(); OutputStream sout = socket.getOutputStream(); in = new DataInputStream(sin); out = new DataOutputStream(sout); String line = null; while (true) { line = in.readUTF(); /* */ System.out.println("line start sending = " + line); out.writeUTF(data); out.flush(); line = in.readUTF(); System.out.println(line); if (line == "finish") break; else { out.writeUTF("ok"); out.flush(); } } } out.writeUTF("finish"); out.flush(); in.close(); out.close(); socket.close(); } catch (Exception x) { errors += x.toString() + " ;\n"; error_flag = true; } }