List of usage examples for java.io DataInputStream available
public int available() throws IOException
From source file:ubic.gemma.analysis.preprocess.batcheffects.AffyScanDateExtractor.java
private String readGCOSString(DataInputStream str) throws IOException { int fieldLength = readIntLittleEndian(str); StringBuilder buf = new StringBuilder(); for (int i = 0; i < fieldLength; i++) { if (str.available() == 0) throw new IOException("Reached end of file without string end"); buf.append(new String(new byte[] { str.readByte() }, "US-ASCII")); }//from w w w . j a v a 2 s . c o m String field = buf.toString(); return field; }
From source file:com.atlassian.extras.decoder.v2.Version2LicenseDecoder.java
private byte[] checkAndGetLicenseText(String licenseContent) { try {//from w ww.j a v a2 s . c om byte[] decodedBytes = Base64.decodeBase64(licenseContent.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes); DataInputStream dIn = new DataInputStream(in); int textLength = dIn.readInt(); byte[] licenseText = new byte[textLength]; dIn.read(licenseText); byte[] hash = new byte[dIn.available()]; dIn.read(hash); /*try { Signature signature = Signature.getInstance("SHA1withDSA"); signature.initVerify(PUBLIC_KEY); signature.update(licenseText); if (!signature.verify(hash)) { throw new LicenseException("Failed to verify the license."); } } catch (InvalidKeyException e) { throw new LicenseException(e); } catch (SignatureException e) { throw new LicenseException(e); } catch (NoSuchAlgorithmException e) { throw new LicenseException(e); }*/ return licenseText; } catch (IOException e) { throw new LicenseException(e); } }
From source file:BA.Server.FileUpload.java
/** * Handles the HTTP <code>POST</code> method. * @param request servlet request/*from ww w. j ava2 s. co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @SuppressWarnings("unchecked") protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter outp = resp.getWriter(); PrintWriter writer = null; try { writer = resp.getWriter(); } catch (IOException ex) { log(FileUpload.class.getName() + "has thrown an exception: " + ex.getMessage()); } StringBuffer buff = new StringBuffer(); File file1 = (File) req.getAttribute("file"); if (file1 == null || !file1.exists()) { System.out.println("File does not exist"); } else if (file1.isDirectory()) { System.out.println("File is a directory"); } else { File outputFile = new File("/tmp/" + req.getParameter("file")); file1.renameTo(outputFile); FileInputStream f = new FileInputStream(outputFile); // Here BufferedInputStream is added for fast reading. BufferedInputStream bis = new BufferedInputStream(f); DataInputStream dis = new DataInputStream(bis); int i = 0; String result = ""; writer.write("<html>"); writer.write("<head><script type='text/javascript'>"); while (dis.available() != 0) { String current = dis.readLine(); if (((String) req.getParameter("uploadType")).equals("equations")) { if (FormulaTester.testInput(current) == -1) { writer.write("window.opener.addTabExt(\"" + current + "\" , \"" + req.getParameter("file") + "\");"); } } else { writer.write("window.opener.addMacroExt(\"" + current + "\");"); } i++; } writer.write("this.close();</script></head>"); writer.write("</script></head>"); writer.write("<body>"); writer.write("</body>"); writer.write("</html>"); writer.flush(); writer.close(); dis.close(); bis.close(); f.close(); outputFile.delete(); } }
From source file:org.apache.cassandra.db.SuperColumn.java
private void fillSuperColumn(IColumn superColumn, DataInputStream dis) throws IOException { assert dis.available() != 0; /* read the number of columns */ int size = dis.readInt(); /* read the size of all columns */ dis.readInt();/*from ww w.j a v a 2 s . co m*/ for (int i = 0; i < size; ++i) { IColumn subColumn = Column.serializer().deserialize(dis); superColumn.addColumn(subColumn.name(), subColumn); } }
From source file:Version2LicenseDecoder.java
private byte[] checkAndGetLicenseText(String licenseContent) { try {/*ww w .ja v a2 s. c om*/ byte[] e = Base64.decodeBase64(licenseContent.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(e); DataInputStream dIn = new DataInputStream(in); int textLength = dIn.readInt(); byte[] licenseText = new byte[textLength]; dIn.read(licenseText); byte[] hash = new byte[dIn.available()]; dIn.read(hash); try { Signature e1 = Signature.getInstance("SHA1withDSA"); e1.initVerify(PUBLIC_KEY); e1.update(licenseText); if (!e1.verify(hash)) { throw new LicenseException("Failed to verify the license."); } else { return licenseText; } } catch (InvalidKeyException var9) { throw new LicenseException(var9); } catch (SignatureException var10) { throw new LicenseException(var10); } catch (NoSuchAlgorithmException var11) { throw new LicenseException(var11); } } catch (IOException var12) { throw new LicenseException(var12); } }
From source file:org.apache.cassandra.db.SuperColumn.java
public IColumn deserialize(DataInputStream dis, IFilter filter) throws IOException { if (dis.available() == 0) return null; IColumn superColumn = defreezeSuperColumn(dis); superColumn = filter.filter(superColumn, dis); if (superColumn != null) { fillSuperColumn(superColumn, dis); return superColumn; } else {//from w w w . ja v a 2s.com /* read the number of columns stored */ dis.readInt(); /* read the size of all columns to skip */ int size = dis.readInt(); dis.skip(size); return null; } }
From source file:com.facebook.infrastructure.db.SuperColumn.java
private void fillSuperColumn(IColumn superColumn, DataInputStream dis) throws IOException { if (dis.available() == 0) return;// ww w . ja v a 2s .co m /* read the number of columns */ int size = dis.readInt(); /* read the size of all columns */ dis.readInt(); for (int i = 0; i < size; ++i) { IColumn subColumn = Column.serializer().deserialize(dis); superColumn.addColumn(subColumn.name(), subColumn); } }
From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java
protected List<VVertex> readVertices(VSubGraph graph, DataInputStream stream) throws IOException { List<VVertex> vertices = new ArrayList<VVertex>(); while (stream.available() > 0) { long id = readElementId(stream); String label = readElementLabel(stream); List<VEdge> edges = readVertexEdge(graph, id, stream); VVertex vertex = new VVertex(graph, id, label); vertex.getEdges().addAll(edges); vertices.add(vertex);//w w w . j av a 2 s . c o m } return vertices; }
From source file:com.vimukti.accounter.license.LicenseManager.java
private byte[] checkAndGetLicenseText(String licenseContent) { byte[] licenseText; try {/*from w ww. j av a 2s. c om*/ byte[] decodedBytes = Base64.decodeBase64(licenseContent.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes); DataInputStream dIn = new DataInputStream(in); int textLength = dIn.readInt(); licenseText = new byte[textLength]; dIn.read(licenseText); byte[] hash = new byte[dIn.available()]; dIn.read(hash); try { Signature signature = Signature.getInstance("SHA1withDSA"); signature.initVerify(PUBLIC_KEY); signature.update(licenseText); if (!signature.verify(hash)) { throw new LicenseException("Failed to verify the license."); } } catch (InvalidKeyException e) { throw new LicenseException(e); } catch (SignatureException e) { throw new LicenseException(e); } catch (NoSuchAlgorithmException e) { throw new LicenseException(e); } } catch (IOException e) { throw new LicenseException(e); } return licenseText; }
From source file:com.facebook.infrastructure.db.SuperColumn.java
public IColumn deserialize(DataInputStream dis, IFilter filter) throws IOException { if (dis.available() == 0) return null; IColumn superColumn = defreezeSuperColumn(dis); superColumn = filter.filter(superColumn, dis); if (superColumn != null) { if (!superColumn.isMarkedForDelete()) fillSuperColumn(superColumn, dis); return superColumn; } else {// ww w.j av a2 s . c om /* read the number of columns stored */ dis.readInt(); /* read the size of all columns to skip */ int size = dis.readInt(); dis.skip(size); return null; } }