List of usage examples for java.io DataInputStream close
public void close() throws IOException
From source file:net.contextfw.web.application.internal.development.ReloadingClassLoader.java
private byte[] loadClassData(String className) throws IOException { InputStream stream = super.getResourceAsStream(className.replaceAll("\\.", "/") + ".class"); if (stream != null) { DataInputStream dis = new DataInputStream(stream); // NOSONAR byte buff[] = IOUtils.toByteArray(stream); dis.close(); return buff; } else {/*from w w w.j a v a2 s . c om*/ return null; } }
From source file:org.cloudata.core.tablet.backup.RestoreBinaryPartitionMap.java
@Override public void map(BytesWritable key, BytesWritable value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(key.get(), 0, key.getSize()); DataInputStream in = new DataInputStream(bin); Row row = new Row(); row.readFields(in);/*w w w . jav a2 s .c om*/ lastRow = row; in.close(); }
From source file:isl.FIMS.utils.Utils.java
public static void downloadZip(ServletOutputStream outStream, File file) { DataInputStream in = null; int BUFSIZE = 8192; try {/*from w w w . j a v a 2s . c om*/ byte[] byteBuffer = new byte[BUFSIZE]; in = new DataInputStream(new FileInputStream(file)); int bytesRead; while ((bytesRead = in.read(byteBuffer)) != -1) { outStream.write(byteBuffer, 0, bytesRead); } in.close(); outStream.close(); } catch (IOException ex) { } finally { try { in.close(); } catch (IOException ex) { } } }
From source file:com.sinpo.xnfc.nfc.Util.java
public static String execRootCmd(String cmd) { String result = ""; DataOutputStream dos = null;/* w w w .j a va2s . co m*/ DataInputStream dis = null; try { Process p = Runtime.getRuntime().exec("su"); dos = new DataOutputStream(p.getOutputStream()); dis = new DataInputStream(p.getInputStream()); dos.writeBytes(cmd + "\n"); dos.flush(); dos.writeBytes("exit\n"); dos.flush(); String line = null; while ((line = dis.readLine()) != null) { result += line + "\r\n"; } p.waitFor(); } catch (Exception e) { e.printStackTrace(); } finally { if (dos != null) { try { dos.close(); } catch (IOException e) { e.printStackTrace(); } } if (dis != null) { try { dis.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }
From source file:com.bonsai.wallet32.HDWallet.java
public static JSONObject deserialize(WalletApplication walletApp, KeyCrypter keyCrypter, KeyParameter aesKey) throws IOException, InvalidCipherTextException, JSONException { File file = walletApp.getHDWalletFile(null); String path = file.getPath(); try {//ww w. j a v a2s. c o m mLogger.info("restoring HDWallet from " + path); int len = (int) file.length(); // Open persisted file. DataInputStream dis = new DataInputStream(new FileInputStream(file)); // Read IV from file. byte[] iv = new byte[KeyCrypterGroestl.BLOCK_LENGTH/*KeyCrypterScrypt.BLOCK_LENGTH*/]; dis.readFully(iv); // Read the ciphertext from the file. byte[] cipherBytes = new byte[len - iv.length]; dis.readFully(cipherBytes); dis.close(); // Decrypt the ciphertext. ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), iv); BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine())); cipher.init(false, keyWithIv); int minimumSize = cipher.getOutputSize(cipherBytes.length); byte[] outputBuffer = new byte[minimumSize]; int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, outputBuffer, 0); int length2 = cipher.doFinal(outputBuffer, length1); int actualLength = length1 + length2; byte[] decryptedBytes = new byte[actualLength]; System.arraycopy(outputBuffer, 0, decryptedBytes, 0, actualLength); // Parse the decryptedBytes. String jsonstr = new String(decryptedBytes); /* // THIS CONTAINS THE SEED! // Have to break the message into chunks for big messages ... String msg = jsonstr; while (msg.length() > 1024) { String chunk = msg.substring(0, 1024); mLogger.error(chunk); msg = msg.substring(1024); } mLogger.error(msg); */ JSONObject node = new JSONObject(jsonstr); return node; } catch (IOException ex) { mLogger.warn("trouble reading " + path + ": " + ex.toString()); throw ex; } catch (RuntimeException ex) { mLogger.warn("trouble restoring wallet: " + ex.toString()); throw ex; } catch (InvalidCipherTextException ex) { mLogger.warn("wallet decrypt failed: " + ex.toString()); throw ex; } }
From source file:com.tactfactory.harmony.utils.TactFileUtils.java
/** convert file content to a string array with each line separated. * @param file The File to read/*w ww .jav a2 s . c o m*/ * @return Array of Strings containing the file contents */ public static List<String> fileToStringArray(final File file) { ArrayList<String> result = null; String line = null; DataInputStream inStream = null; BufferedReader bReader = null; try { result = new ArrayList<String>(); inStream = new DataInputStream(new FileInputStream(file)); bReader = new BufferedReader(new InputStreamReader(inStream, TactFileUtils.DEFAULT_ENCODING)); line = bReader.readLine(); while (line != null) { result.add(line); line = bReader.readLine(); } } catch (final IOException e) { throw new RuntimeException("IO problem in fileToString", e); } finally { try { if (inStream != null) { inStream.close(); } if (bReader != null) { bReader.close(); } } catch (final IOException e) { ConsoleUtils.displayError(e); } } return result; }
From source file:io.undertow.servlet.test.proprietry.TransferTestCase.java
@Test public void testServletRequest() throws Exception { TestListener.init(2);//from ww w .jav a2s . co m TestHttpClient client = new TestHttpClient(); try { HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); final byte[] response = HttpClientUtils.readRawResponse(result); Path file = Paths.get(TXServlet.class.getResource(TXServlet.class.getSimpleName() + ".class").toURI()); byte[] expected = new byte[(int) Files.size(file)]; DataInputStream dataInputStream = new DataInputStream(Files.newInputStream(file)); dataInputStream.readFully(expected); dataInputStream.close(); Assert.assertArrayEquals(expected, response); } finally { client.getConnectionManager().shutdown(); } }
From source file:com.uber.hoodie.common.BloomFilter.java
/** * Create the bloom filter from serialized string. *//* w w w . j a va 2 s . c om*/ public BloomFilter(String filterStr) { this.filter = new org.apache.hadoop.util.bloom.BloomFilter(); byte[] bytes = DatatypeConverter.parseBase64Binary(filterStr); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); try { this.filter.readFields(dis); dis.close(); } catch (IOException e) { throw new HoodieIndexException("Could not deserialize BloomFilter instance", e); } }
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 . j a va 2s. 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:Main.java
public static Object[] readSettings(String file) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); try {//from ww w. jav a2 s.com Object[] res = new Object[in.readInt()]; for (int i = 0; i < res.length; i++) { char cl = in.readChar(); switch (cl) { case 'S': res[i] = in.readUTF(); break; case 'F': res[i] = in.readFloat(); break; case 'D': res[i] = in.readDouble(); break; case 'I': res[i] = in.readInt(); break; case 'L': res[i] = in.readLong(); break; case 'B': res[i] = in.readBoolean(); break; case 'Y': res[i] = in.readByte(); break; default: throw new IllegalStateException("cannot read type " + cl + " from " + file); } } return res; } finally { in.close(); } }