List of usage examples for java.io BufferedInputStream close
public void close() throws IOException
From source file:org.mumod.util.ImageManager.java
public Bitmap fetchImage(String url) throws IOException { // Log.d(TAG, "Fetching image: " + url); HttpGet get = new HttpGet(url); HttpConnectionParams.setConnectionTimeout(get.getParams(), CONNECTION_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(get.getParams(), SOCKET_TIMEOUT_MS); HttpResponse response;// w ww . j ava 2 s . c om try { response = mClient.execute(get); } catch (ClientProtocolException e) { if (MustardApplication.DEBUG) Log.e(TAG, e.getMessage(), e); throw new IOException("Invalid client protocol."); } if (response.getStatusLine().getStatusCode() != 200) { throw new IOException("Non OK response: " + response.getStatusLine().getStatusCode()); } HttpEntity entity = response.getEntity(); BufferedInputStream bis = new BufferedInputStream(entity.getContent(), 8 * 1024); Bitmap bitmap = BitmapFactory.decodeStream(bis); bis.close(); return bitmap; }
From source file:crush.CrushUtil.java
protected void textCrush(FileSystem fs, FileStatus[] status) throws IOException, CrushException { FSDataOutputStream out = fs.create(outPath); BufferedOutputStream bw = new java.io.BufferedOutputStream(out); for (FileStatus stat : status) { BufferedInputStream br = new BufferedInputStream(fs.open(stat.getPath())); byte[] buffer = new byte[2048]; int read = -1; while ((read = br.read(buffer)) != -1) { bw.write(buffer, 0, read);//from w w w . ja va 2 s. c o m } br.close(); } bw.close(); }
From source file:asciidoc.maven.plugin.tools.ZipHelper.java
public void unzipEntry(ZipFile zipfile, ZipEntry zipEntry, File outputDir) throws IOException { if (zipEntry.isDirectory()) { createDir(new File(outputDir, zipEntry.getName())); return;/*from ww w. j a v a 2 s . co m*/ } File outputFile = new File(outputDir, zipEntry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } if (this.log.isDebugEnabled()) this.log.debug("Extracting " + zipEntry); BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(zipEntry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } if ((outputFile != null) && (!outputFile.isDirectory() && FileHelper.getFileExtension(outputFile).equalsIgnoreCase("py"))) { outputFile.setExecutable(true); } }
From source file:raymond.mockftpserver.S3CachedFtpServer.java
private void readKeyFile(File _accessFile) throws IOException, EncryptionException { logger.info("@@ reading cypher from:" + _accessFile); BufferedInputStream in = new BufferedInputStream(new FileInputStream(_accessFile)); int len = in.available(); byte[] buffer = new byte[len]; in.read(buffer);// w w w. java 2 s.c om in.close(); logger.info("@@ len read is:" + len); byte[] cleartext; Encryptor crypt = new ThreeDESEncryptor(chave + keyBase); cleartext = crypt.decrypt(buffer); int nameLen = cleartext[0]; int accessKeyLen = cleartext[1]; int secretKeyLen = cleartext.length - 2 - nameLen - accessKeyLen; if (secretKeyLen % 2 != 0) { throw new RuntimeException("internal error: secret key has odd bytecount"); } byte[] nameRaw = new byte[nameLen]; for (int i = 0; i < nameLen; i++) { nameRaw[i] = cleartext[i + 2]; } String nameCheck = new String(nameRaw, charset); if (!chave.equals(nameCheck)) { throw new RuntimeException("internal error: secret key name mismatch"); } // Get the Access Key int offset = 2 + nameLen; byte[] accessKeyRaw = new byte[accessKeyLen]; for (int i = 0; i < accessKeyLen; i++) { accessKeyRaw[i] = cleartext[i + offset]; } apiKey = new String(accessKeyRaw, charset); // Get the Secret Key char[] secretKey = new char[secretKeyLen / 2]; offset += accessKeyLen; for (int i = 0; i < secretKeyLen / 2; i++) { int spot = i + i + offset; char ch = (char) ((cleartext[spot] << 8) + cleartext[spot + 1]); secretKey[i] = ch; } apiKeySecret = new String(secretKey); }
From source file:com.teletalk.jserver.util.SpillOverByteArrayOutputStream.java
/** * Writes the contents of this stream to the specified output stream. *//* w ww . j a v a2 s . c o m*/ public void writeTo(final OutputStream out) throws IOException { if (this.hasSpilledOver()) { this.spillOverFileOutputStream.flush(); BufferedInputStream input = new BufferedInputStream(new FileInputStream(this.spillOverFile)); StreamCopyUtils.copy(input, out, this.bytesWritten); input.close(); } else if (this.byteArrayOutputStream != null) this.byteArrayOutputStream.writeTo(out); }
From source file:fr.fastconnect.factory.tibco.bw.fcunit.PrepareTestMojo.java
private boolean containsString(String string, InputStream fileInZip) throws IOException { boolean result = false; BufferedInputStream lzf = new BufferedInputStream(fileInZip); FindStringInInputStream ris = new FindStringInInputStream(lzf); result = ris.containsString(string); ris.close();//from w ww .j a va2 s . c o m lzf.close(); return result; }
From source file:CharsetDetector.java
private Charset detectCharset(File f, Charset charset) { try {/* w ww .j a va 2s . com*/ BufferedInputStream input = new BufferedInputStream(new FileInputStream(f)); CharsetDecoder decoder = charset.newDecoder(); decoder.reset(); byte[] buffer = new byte[512]; boolean identified = false; while ((input.read(buffer) != -1) && (!identified)) { identified = identify(buffer, decoder); } input.close(); if (identified) { return charset; } else { return null; } } catch (Exception e) { return null; } }
From source file:asciidoc.maven.plugin.AbstractAsciiDocMojo.java
private void unzipEntry(ZipFile zipfile, ZipEntry zipEntry, File outputDir) throws IOException { if (zipEntry.isDirectory()) { createDir(new File(outputDir, zipEntry.getName())); return;//from w ww . j a va 2 s . co m } File outputFile = new File(outputDir, zipEntry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } if (getLog().isDebugEnabled()) getLog().debug("Extracting " + zipEntry); BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(zipEntry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } }
From source file:JarMaker.java
/** * Combine several jar files and some given files into one jar file. * @param outJar The output jar file's filename. * @param inJarsList The jar files to be combined * @param filter A filter that exclude some entries of input jars. User * should implement the EntryFilter interface. * @param inFileList The files to be added into the jar file. * @param prefixs The prefixs of files to be added into the jar file. * inFileList and prefixs should be paired. * @throws FileNotFoundException/*from w w w. j av a2s . co m*/ * @throws IOException */ @SuppressWarnings("unchecked") public static void combineJars(String outJar, String[] inJarsList, EntryFilter filter, String[] inFileList, String[] prefixs) throws FileNotFoundException, IOException { JarOutputStream jout = new JarOutputStream(new FileOutputStream(outJar)); ArrayList entryList = new ArrayList(); for (int i = 0; i < inJarsList.length; i++) { BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(inJarsList[i])); ZipInputStream zipinputstream = new ZipInputStream(bufferedinputstream); byte abyte0[] = new byte[1024 * 4]; for (ZipEntry zipentry = zipinputstream.getNextEntry(); zipentry != null; zipentry = zipinputstream .getNextEntry()) { if (filter.accept(zipentry)) { if (!entryList.contains(zipentry.getName())) { jout.putNextEntry(zipentry); if (!zipentry.isDirectory()) { int j; try { while ((j = zipinputstream.read(abyte0, 0, abyte0.length)) != -1) jout.write(abyte0, 0, j); } catch (IOException ie) { throw ie; } } entryList.add(zipentry.getName()); } } } zipinputstream.close(); bufferedinputstream.close(); } for (int i = 0; i < inFileList.length; i++) { add(jout, new File(inFileList[i]), prefixs[i]); } jout.close(); }
From source file:com.teasoft.teavote.util.Signature.java
public boolean verifyFile(String pathToFile) throws FileNotFoundException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException, SignatureException, InvalidKeySpecException { File fileToVerify = new File(pathToFile); FileInputStream originalFileIs = new FileInputStream(fileToVerify); String dataPathToVerify = new ConfigLocation().getConfigPath() + File.separator + "dataToVerify.sql"; File dataToVerify = new File(dataPathToVerify); FileOutputStream fw = new FileOutputStream(dataToVerify); //Read the caution message and signature out byte[] cautionMsg = new byte[175]; //Caution section occupies 175 bytes originalFileIs.read(cautionMsg);// w w w . jav a 2s. c o m //Read and Write the rest of the bytes in original file into data to verify byte[] buffer = new byte[1024]; int nRead = 0; while ((nRead = originalFileIs.read(buffer)) != -1) { fw.write(buffer, 0, nRead); } //Close originalFileIs and dataToVerify originalFileIs.close(); fw.close(); //Get signature from caution/signation message byte[] sigToVerify = new byte[64]; for (int i = 0, j = 0; i < cautionMsg.length; i++) { if (i >= 106 && i < 170) { sigToVerify[j++] = cautionMsg[i]; } } //decode signature bytes sigToVerify = Base64.decodeBase64(sigToVerify); // sigToVerify = com.sun.org.apache.xml.internal.security.utils.Base64.decode(sigToVerify); java.security.Signature sig = java.security.Signature.getInstance("SHA1withDSA", "SUN"); sig.initVerify(getPublicKey()); //Get digital signature FileInputStream datafis = new FileInputStream(dataPathToVerify); BufferedInputStream bufin = new BufferedInputStream(datafis); int len; while (bufin.available() != 0) { len = bufin.read(buffer); sig.update(buffer, 0, len); } bufin.close(); //Delete fileToVerify dataToVerify.delete(); return sig.verify(sigToVerify); }