List of usage examples for java.io BufferedInputStream read
public synchronized int read(byte b[], int off, int len) throws IOException
From source file:net.firejack.platform.core.utils.ArchiveUtils.java
/** * @param basePath// w w w . j a v a 2 s .c o m * @param tarPath * @param filePaths * @throws java.io.IOException */ public static void tar(String basePath, String tarPath, Map<String, String> filePaths) throws IOException { BufferedInputStream origin = null; TarArchiveOutputStream out = null; FileOutputStream dest = null; try { dest = new FileOutputStream(tarPath); out = new TarArchiveOutputStream(new BufferedOutputStream(dest)); byte data[] = new byte[BUFFER]; for (Map.Entry<String, String> entryFile : filePaths.entrySet()) { String filename = entryFile.getKey(); String filePath = entryFile.getValue(); System.out.println("Adding: " + filename + " => " + filePath); FileInputStream fi = new FileInputStream(basePath + filePath); origin = new BufferedInputStream(fi, BUFFER); TarArchiveEntry entry = new TarArchiveEntry(filename); out.putArchiveEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } origin.close(); } } catch (Exception e) { e.printStackTrace(); } finally { if (origin != null) origin.close(); if (out != null) out.close(); if (dest != null) dest.close(); } }
From source file:br.univali.celine.lms.utils.zip.Zip.java
public void zip(ArrayList<String> fileList, File destFile, int compressionLevel) throws Exception { if (destFile.exists()) throw new Exception("File " + destFile.getName() + " already exists!!"); int fileLength; byte[] buffer = new byte[4096]; FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream bos = new BufferedOutputStream(fos); ZipOutputStream zipFile = new ZipOutputStream(bos); zipFile.setLevel(compressionLevel);/*from w w w . j a v a 2 s.c om*/ for (int i = 0; i < fileList.size(); i++) { FileInputStream fis = new FileInputStream(fileList.get(i)); BufferedInputStream bis = new BufferedInputStream(fis); ZipEntry ze = new ZipEntry(FilenameUtils.getName(fileList.get(i))); zipFile.putNextEntry(ze); while ((fileLength = bis.read(buffer, 0, 4096)) > 0) zipFile.write(buffer, 0, fileLength); zipFile.closeEntry(); bis.close(); } zipFile.close(); }
From source file:net.sf.zekr.engine.translation.TranslationData.java
private boolean verify(InputStream is, byte[] textBuf) throws IOException { BufferedInputStream bis = new BufferedInputStream(is, 262144); bis.read(textBuf, 0, textBuf.length); logger.debug("Verifying translation text."); try {//w w w . ja v a2 s.co m verified = CryptoUtils.verify(textBuf, signature); } catch (Exception e) { logger.warn("Error occurred during translation text verification. Text cannot be verified.", e); } if (verified) { logger.debug("Translation is valid"); verificationResult = AUTHENTIC; } else { logger.debug("Translation is not valid."); verificationResult = NOT_AUTHENTIC; } return verified; }
From source file:it.readbeyond.minstrel.librarian.FormatHandlerAbstractZIP.java
protected String getZipEntryText(ZipFile zipFile, ZipEntry ze) { String toReturn = ""; try {//from w w w . j a v a2 s. c om BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(ze)); byte[] bytes = new byte[(int) (ze.getSize())]; is.read(bytes, 0, bytes.length); is.close(); toReturn = new String(bytes); } catch (Exception e) { // nothing } return toReturn; }
From source file:gr.forth.ics.isl.x3mlEditor.upload.UploadReceiver.java
/** * * @param f//from ww w . ja v a 2s. c o m * @param enc * @return */ private String readFile(File f, String enc) { try { BufferedInputStream in = new BufferedInputStream(new FileInputStream(f)); byte[] arr = new byte[(int) f.length()]; in.read(arr, 0, arr.length); in.close(); return new String(arr, enc); } catch (Exception ex) { ex.printStackTrace(System.out); throw new Error("IO Error in readFile"); } }
From source file:edu.harvard.iq.dataverse.ingest.metadataextraction.impl.plugins.fits.FITSFileMetadataExtractorSpi.java
@Override public boolean canDecodeInput(BufferedInputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("stream == null!"); }//from w ww . j a v a 2s . c o m byte[] b = new byte[FITS_HEADER_SIZE]; if (stream.markSupported()) { stream.mark(0); } int nbytes = stream.read(b, 0, FITS_HEADER_SIZE); if (nbytes == 0) { throw new IOException(); } //printHexDump(b, "hex dump of the byte-array"); dbgLog.info("hex dump of the 1st " + FITS_HEADER_SIZE + " bytes:" + (new String(Hex.encodeHex(b))).toUpperCase()); if (stream.markSupported()) { stream.reset(); } boolean DEBUG = false; String hdr4fits = new String(b); if (hdr4fits.equals(FITS_FILE_SIGNATURE)) { dbgLog.fine("this is a fits file"); return true; } else { dbgLog.fine("this is NOT a fits file"); return false; } }
From source file:Main.java
public static String zip(String filename) throws IOException { BufferedInputStream origin = null; Integer BUFFER_SIZE = 20480;// w ww. ja va 2 s.com if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { File flockedFilesFolder = new File( Environment.getExternalStorageDirectory() + File.separator + "FlockLoad"); System.out.println("FlockedFileDir: " + flockedFilesFolder); String uncompressedFile = flockedFilesFolder.toString() + "/" + filename; String compressedFile = flockedFilesFolder.toString() + "/" + "flockZip.zip"; ZipOutputStream out = new ZipOutputStream( new BufferedOutputStream(new FileOutputStream(compressedFile))); out.setLevel(9); try { byte data[] = new byte[BUFFER_SIZE]; FileInputStream fi = new FileInputStream(uncompressedFile); System.out.println("Filename: " + uncompressedFile); System.out.println("Zipfile: " + compressedFile); origin = new BufferedInputStream(fi, BUFFER_SIZE); try { ZipEntry entry = new ZipEntry( uncompressedFile.substring(uncompressedFile.lastIndexOf("/") + 1)); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) { out.write(data, 0, count); } } finally { origin.close(); } } finally { out.close(); } return "flockZip.zip"; } return null; }
From source file:com.freshplanet.ane.GoogleCloudStorageUpload.tasks.UploadToGoogleCloudStorageAsyncTask.java
private byte[] getImageByteArray(String path) { Log.d(TAG, "[UploadToGoogleCloudStorageAsyncTask] Entering getImageByteArray()"); File file = new File(path); int size = (int) file.length(); byte[] bytes = new byte[size]; BufferedInputStream buf; try {/* w ww. j a v a2 s .c o m*/ buf = new BufferedInputStream(new FileInputStream(file)); buf.read(bytes, 0, bytes.length); buf.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.d(TAG, "[UploadToGoogleCloudStorageAsyncTask] Exiting getImageByteArray()"); return bytes; }
From source file:com.freshplanet.ane.GoogleCloudStorageUpload.tasks.UploadToGoogleCloudStorageAsyncTask.java
private byte[] createHeaderByteArrayFile(byte[] prefix, byte[] suffix, String path) { Log.d(TAG, "[UploadToGoogleCloudStorageAsyncTask] Entering createHeaderByteArrayVideo()"); File file = new File(path); int fileLength = (int) file.length(); int size = fileLength + prefix.length + suffix.length; byte[] bytes = new byte[size]; System.arraycopy(prefix, 0, bytes, 0, prefix.length); BufferedInputStream buf; try {//from w ww . jav a2s .c o m buf = new BufferedInputStream(new FileInputStream(file)); buf.read(bytes, prefix.length, fileLength); buf.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.arraycopy(suffix, 0, bytes, fileLength + prefix.length, suffix.length); Log.d(TAG, "[UploadToGoogleCloudStorageAsyncTask] Exiting createHeaderByteArrayVideo()"); return bytes; }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.sav.SAVFileReaderSpi.java
@Override public boolean canDecodeInput(Object source) throws IOException { out.println("this method is actually called: object"); if (!(source instanceof BufferedInputStream)) { return false; } else if (source instanceof File) { out.println("source is a File object"); } else {//from w ww.ja va2s.c om out.println("not File object"); } if (source == null) { throw new IllegalArgumentException("source == null!"); } BufferedInputStream stream = (BufferedInputStream) source; dbgLog.fine("applying the sav test\n"); byte[] b = new byte[SAV_HEADER_SIZE]; if (stream.markSupported()) { stream.mark(0); } int nbytes = stream.read(b, 0, SAV_HEADER_SIZE); if (nbytes == 0) { throw new IOException(); } //printHexDump(b, "hex dump of the byte-array"); dbgLog.info("hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b))); if (stream.markSupported()) { stream.reset(); } boolean DEBUG = false; String hdr4sav = new String(b); dbgLog.fine("from string[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)).toUpperCase()); if (hdr4sav.equals(SAV_FILE_SIGNATURE)) { dbgLog.fine("this file is spss-sav type"); return true; } else { dbgLog.fine("this file is NOT spss-sav type"); return false; } }