List of usage examples for java.io BufferedInputStream BufferedInputStream
public BufferedInputStream(InputStream in)
BufferedInputStream
and saves its argument, the input stream in
, for later use. From source file:librarymanagementsystem.Base64Converter.java
/** * This method loads a file from file system and returns the byte array of * the content.//from w ww.java2 s. c o m */ public static byte[] loadFileAsBytesArray(String fileName) throws Exception { File file = new File(fileName); int length = (int) file.length(); BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file)); byte[] bytes = new byte[length]; reader.read(bytes, 0, length); reader.close(); return bytes; }
From source file:edu.yale.cs.hadoopdb.util.HDFSUtil.java
/** * Reads a text file into a set of integer (each value in a separate line) *//*from w ww. ja v a2s . com*/ public static void readIntegerSet(Path path, Set<Integer> set) throws IOException { FSDataInputStream in = getFS().open(path); LineReader lineReader = new LineReader(new BufferedInputStream(in)); Text line = new Text(); while (lineReader.readLine(line) > 0) { String s = line.toString().trim(); int value = Integer.parseInt(s); set.add(value); } in.close(); }
From source file:com.abid_mujtaba.bitcoin.tracker.network.Client.java
private static String get(String url_string) throws ClientException { HttpURLConnection connection = null; // NOTE: fetchImage is set up to use HTTP not HTTPS try {/*from w ww.j av a 2 s . com*/ URL url = new URL(url_string); connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(CONNECTION_TIMEOUT); connection.setReadTimeout(READ_TIMEOUT); InputStream is = new BufferedInputStream(connection.getInputStream()); int response_code; if ((response_code = connection.getResponseCode()) != 200) { throw new ClientException("Error code returned by response: " + response_code); } return InputStreamToString(is); } catch (SocketTimeoutException e) { throw new ClientException("Socket timed out.", e); } catch (IOException e) { throw new ClientException("IO Exception raised while attempting to GET response.", e); } finally { if (connection != null) { connection.disconnect(); } } }
From source file:give_me_coins.dashboard.JSONHelper.java
private static JSONObject getJSONFromUrl(URL para_url) { // ProgressDialog oShowProgress = ProgressDialog.show(oAct, "Loading", "Loading", true, false); JSONObject oRetJson = null;// w ww . j a v a 2 s . com try { //Log.d(TAG,para_url.toString()); BufferedInputStream oInput = null; HttpsURLConnection oConnection = (HttpsURLConnection) para_url.openConnection(); // HttpsURLConnection.setDefaultHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); oConnection.setConnectTimeout(iConnectionTimeout); oConnection.setReadTimeout(iConnectionTimeout * 2); // connection.setRequestProperty ("Authorization", sAuthorization); oConnection.connect(); oInput = new BufferedInputStream(oConnection.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(oInput)); String sReturn = reader.readLine(); //Log.d(TAG,sReturn); oRetJson = new JSONObject(sReturn); } catch (SocketTimeoutException e) { Log.d(TAG, "Timeout"); } catch (IOException e) { Log.e(TAG, e.toString()); } catch (JSONException e) { Log.e(TAG, e.toString()); } catch (Exception e) { Log.e(TAG, e.toString()); } //para_ProgressDialog.dismiss(); return oRetJson; }
From source file:org.deshang.content.indexing.util.jdbc.AbstractRowMapper.java
protected String getBlobContent(Blob blob) throws SQLException { LOGGER.debug("Enter getBlobContent(Blob)"); String blobContent = null;//w ww. j a va 2s . c o m try { InputStream in = blob.getBinaryStream(); BufferedInputStream bis = new BufferedInputStream(in); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int data = -1; while ((data = bis.read()) != -1) { baos.write(data); } blobContent = baos.toString("UTF-8"); } catch (IOException e) { throw new SQLException("Can't read blob conent", e); } LOGGER.debug("Exit getBlobContent(Blob)"); return blobContent; }
From source file:com.iyonger.apm.web.util.FileDownloadUtils.java
/** * Download the given file to the given {@link HttpServletResponse}. * * @param response {@link HttpServletResponse} * @param file file path/*w ww . j a v a 2 s . c om*/ * @return true if succeeded */ public static boolean downloadFile(HttpServletResponse response, File file) { if (file == null || !file.exists()) { return false; } boolean result = true; response.reset(); response.addHeader("Content-Disposition", "attachment;filename=" + file.getName()); response.setContentType("application/octet-stream"); response.addHeader("Content-Length", "" + file.length()); InputStream fis = null; byte[] buffer = new byte[FILE_DOWNLOAD_BUFFER_SIZE]; OutputStream toClient = null; try { fis = new BufferedInputStream(new FileInputStream(file)); toClient = new BufferedOutputStream(response.getOutputStream()); int readLength; while (((readLength = fis.read(buffer)) != -1)) { toClient.write(buffer, 0, readLength); } toClient.flush(); } catch (FileNotFoundException e) { LOGGER.error("file not found:" + file.getAbsolutePath(), e); result = false; } catch (IOException e) { LOGGER.error("read file error:" + file.getAbsolutePath(), e); result = false; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(toClient); } return result; }
From source file:fr.asso.vieillescharrues.parseurs.TelechargeFichier.java
/** * Mthode statique grant le tlechargement de fichiers * @param url Adresse du fichier//from w ww .j a v a2s . co m * @param fichierDest Nom du ficher en local */ public static void DownloadFromUrl(URL url, String fichierDest) throws IOException { File file; if (fichierDest.endsWith(".jpg")) file = new File(PATH + "images/", fichierDest); else file = new File(PATH, fichierDest); file.getParentFile().mkdirs(); URLConnection ucon = url.openConnection(); try { tailleDistant = ucon.getHeaderFieldInt("Content-Length", 0); //Rcupre le header HTTP Content-Length tailleLocal = (int) file.length(); } catch (Exception e) { e.printStackTrace(); } // Compare les tailles des fichiers if ((tailleDistant == tailleLocal) && (tailleLocal != 0)) return; InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray()); fos.close(); }
From source file:io.github.blindio.prospero.core.browserdrivers.phantomjs.ZipUnArchiver.java
public void extract() { /** create a TarArchiveInputStream object. **/ try {//from w w w .j ava 2s .co m FileInputStream fin = new FileInputStream(getSourceFile()); BufferedInputStream in = new BufferedInputStream(fin); ArchiveInputStream arcIn = new ZipArchiveInputStream(in); extract(arcIn); } catch (IOException ioe) { throw new ProsperoIOException(ioe); } }
From source file:de.flapdoodle.embed.process.extract.TgzExtractor.java
protected ArchiveWrapper archiveStream(File source) throws IOException { FileInputStream fin = new FileInputStream(source); BufferedInputStream in = new BufferedInputStream(fin); GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in); TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); return new TarArchiveWrapper(tarIn); }
From source file:de.flapdoodle.embed.process.extract.Tbz2Extractor.java
@Override protected ArchiveWrapper archiveStream(File source) throws IOException { FileInputStream fin = new FileInputStream(source); BufferedInputStream in = new BufferedInputStream(fin); BZip2CompressorInputStream gzIn = new BZip2CompressorInputStream(in); TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); return new TarArchiveWrapper(tarIn); }