List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:IO.java
public static double[][] readBinaryData(File file, int nData, int nDim) { FileInputStream inStream;/* w ww . j ava 2 s .c o m*/ double[][] data = new double[nData][nDim]; try { inStream = new FileInputStream(file); DataInputStream input = new DataInputStream(inStream); for (int i = 0; i < nData; i++) for (int j = 0; j < nDim; j++) { data[i][j] = input.readDouble(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return data; }
From source file:com.splout.db.benchmark.TCPTest.java
public static void tcpTest(String file, String table) throws UnknownHostException, IOException, InterruptedException, JSONSerDeException { final TCPServer server = new TCPServer(8888, file, table); Thread t = new Thread() { @Override/*from w ww .j a v a 2 s. c o m*/ public void run() { server.serve(); } }; t.start(); while (!server.isServing()) { Thread.sleep(100); } Socket clientSocket = new Socket("localhost", 8888); DataInputStream inFromServer = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())); try { do { // Read a record inFromServer.readUTF(); inFromServer.readInt(); inFromServer.readDouble(); inFromServer.readUTF(); } while (true); } catch (Throwable th) { th.printStackTrace(); } clientSocket.close(); server.stop(); t.interrupt(); }
From source file:org.springdata.ehcache.serializer.DataDeserializer.java
@Override public T deserialize(InputStream inputStream) throws IOException { T obj;/*from www . j a va2s.c om*/ try { obj = entityClass.newInstance(); } catch (Exception e) { throw new IOException(e); } DataSerializable io = (DataSerializable) obj; io.readFields(new DataInputStream(inputStream)); return obj; }
From source file:com.norconex.importer.parser.impl.wordperfect.WPInputStream.java
/** * Constructor./*from w w w . j ava 2s .c o m*/ * @param in input stream */ public WPInputStream(InputStream in) { this.in = new DataInputStream(IOUtil.toBufferedInputStream(in)); }
From source file:br.com.manish.ahy.kernel.util.FileUtil.java
public static byte[] readFileAsBytes(String path) { byte[] fileArray = null; try {//w w w. j a va2 s . c om File file = new File(path); if (file.length() > Integer.MAX_VALUE) { throw new OopsException("Oversized file :-( can't read it, sorry: " + path); } fileArray = new byte[(int) file.length()]; DataInputStream dis; dis = new DataInputStream(new FileInputStream(file)); dis.readFully(fileArray); dis.close(); } catch (Exception e) { throw new OopsException(e, "Problems when reading: [" + path + "]."); } return fileArray; }
From source file:jp.xii.relog.customlibrary.DoSuCommand.java
public boolean init() { boolean ret = false; try {//from w w w .java 2 s . c om //su _process = Runtime.getRuntime().exec("su"); //? _outputStream = new DataOutputStream(_process.getOutputStream()); _inputStream = new DataInputStream(_process.getInputStream()); //??? ret = true; // if(!write("su -v\n")){ // }else{ // String[] results = read().split("\n"); // for (String line : results) { // if(line.length() > 0){ // //??????? // ret = true; // } // } // } } catch (IOException e) { } return ret; }
From source file:Main.java
public InputStream getWWWPageStream(String host, String file) throws IOException, UnknownHostException { InetAddress webServer = InetAddress.getByName(host); Socket httpPipe = new Socket(webServer, 80); if (httpPipe == null) { System.out.println("Socket to Web server creation failed."); return null; }//from w w w . ja v a 2s. co m InputStream inn = httpPipe.getInputStream(); // get raw streams OutputStream outt = httpPipe.getOutputStream(); DataInputStream in = new DataInputStream(inn); // turn into higher-level ones PrintStream out = new PrintStream(outt); if (inn == null || outt == null) { System.out.println("Failed to open streams to socket."); return null; } out.println("GET " + file + " HTTP/1.0\n"); String response; while ((response = in.readUTF()).length() > 0) { System.out.println(response); } return in; }
From source file:com.netflix.aegisthus.io.sstable.IndexDatabaseScanner.java
public IndexDatabaseScanner(@Nonnull InputStream is) { this.countingInputStream = new CountingInputStream(is); this.input = new DataInputStream(this.countingInputStream); }
From source file:delete.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . ja v a2s.c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); Socket s = new Socket("localhost", 9999); DataInputStream in = new DataInputStream(s.getInputStream()); DataOutputStream outD = new DataOutputStream(s.getOutputStream()); outD.writeUTF(request.getParameter("employee_id")); in.readUTF(); s.close(); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("Deleted"); } }
From source file:ca.weblite.contacts.webservice.CN1DataMapperMessageConverter.java
@Override protected Object readInternal(Class type, HttpInputMessage him) throws IOException, HttpMessageNotReadableException { System.out.println("In readInternal"); DataInputStream in = new DataInputStream(him.getBody()); Map m = (Map) com.codename1.io.Util.readObject(in); System.out.println("Read object " + m); return Mappers.getInstance().readMap(m, type); }