List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:uk.ac.sanger.cgp.wwdocker.actions.Utils.java
public static String fileDigest(File file) { String md5;/*from w ww .ja v a 2 s . c o m*/ try { FileInputStream fis = new FileInputStream(file); md5 = DigestUtils.md5Hex(fis); fis.close(); } catch (FileNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } return md5; }
From source file:heigit.ors.util.FileUtility.java
public static String readFile(String fileName, int bufferSize, String encoding) throws IOException { File file = new File(fileName); FileInputStream fis = new FileInputStream(file); String result = StreamUtility.readStream(fis, encoding); fis.close(); return result; }
From source file:com.ikon.util.ArchiveUtils.java
/** * Recursively create ZIP archive from directory helper utility *///from w w w .j a v a 2 s . com private static void createZipHelper(File fs, ZipArchiveOutputStream zaos, String zePath) throws IOException { log.debug("createZipHelper({}, {}, {})", new Object[] { fs, zaos, zePath }); File[] files = fs.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { log.debug("DIRECTORY {}", files[i]); ZipArchiveEntry zae = new ZipArchiveEntry(zePath + "/" + files[i].getName() + "/"); zaos.putArchiveEntry(zae); zaos.closeArchiveEntry(); createZipHelper(files[i], zaos, zePath + "/" + files[i].getName()); } else { log.debug("FILE {}", files[i]); ZipArchiveEntry zae = new ZipArchiveEntry(zePath + "/" + files[i].getName()); zaos.putArchiveEntry(zae); FileInputStream fis = new FileInputStream(files[i]); IOUtils.copy(fis, zaos); fis.close(); zaos.closeArchiveEntry(); } } log.debug("createZipHelper: void"); }
From source file:com.ikon.util.ArchiveUtils.java
/** * Recursively create JAR archive from directory helper utility */// w w w. j a v a 2s . c o m private static void createJarHelper(File fs, JarArchiveOutputStream jaos, String zePath) throws IOException { log.debug("createJarHelper({}, {}, {})", new Object[] { fs, jaos, zePath }); File[] files = fs.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { log.debug("DIRECTORY {}", files[i]); JarArchiveEntry jae = new JarArchiveEntry(zePath + "/" + files[i].getName() + "/"); jaos.putArchiveEntry(jae); jaos.closeArchiveEntry(); createJarHelper(files[i], jaos, zePath + "/" + files[i].getName()); } else { log.debug("FILE {}", files[i]); JarArchiveEntry jae = new JarArchiveEntry(zePath + "/" + files[i].getName()); jaos.putArchiveEntry(jae); FileInputStream fis = new FileInputStream(files[i]); IOUtils.copy(fis, jaos); fis.close(); jaos.closeArchiveEntry(); } } log.debug("createJarHelper: void"); }
From source file:Main.java
public static String readFile(File file) throws Exception { StringBuffer sb = new StringBuffer(); try {//www .j av a 2 s.c om FileInputStream fis = new FileInputStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8")); String line = null; while ((line = br.readLine()) != null) { sb.append(line); } fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (sb.toString().trim().length() <= 0) return null; return sb.toString(); }
From source file:Main.java
/** * Read data from file./*from www.j av a 2 s.c om*/ * * @param fileName * @return */ public static String readFile(String fileName) { String ret = ""; try { FileInputStream fin = new FileInputStream(fileName); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); // ret = EncodingUtils.getString(buffer, "UTF-8"); ret = buffer.toString(); fin.close(); } catch (Exception e) { e.printStackTrace(); } return ret; }
From source file:Main.java
/** * (java) read from file// w w w .j a v a2 s. c o m * * @param path * @return */ public static String readFile(File file) { String str = ""; FileInputStream in; try { in = new FileInputStream(file); int length = (int) file.length(); byte[] temp = new byte[length]; in.read(temp, 0, length); str = EncodingUtils.getString(temp, FILE_ENCODING); in.close(); } catch (IOException e) { Log.e("", "read error!"); } return str; }
From source file:Main.java
public static byte[] getBytesFromFile(File f) { if (f == null) { return null; }//w w w.j a va 2 s. c o m try { FileInputStream stream = new FileInputStream(f); ByteArrayOutputStream out = new ByteArrayOutputStream(1000); byte[] b = new byte[1000]; for (int n; (n = stream.read(b)) != -1;) { out.write(b, 0, n); } stream.close(); out.close(); return out.toByteArray(); } catch (IOException e) { } return null; }
From source file:Main.java
public static byte[] File2byte(String filePath) { byte[] buffer = null; try {//from w w w . ja v a 2s .c o m File file = new File(filePath); FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int n; while ((n = fis.read(b)) != -1) { bos.write(b, 0, n); } fis.close(); bos.close(); buffer = bos.toByteArray(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return buffer; }
From source file:com.jeecms.common.web.ClientCustomSSL.java
public static String getInSsl(String url, File pkcFile, String storeId, String params, String contentType) throws Exception { String text = ""; // ???PKCS12/* ww w . ja v a 2 s. com*/ KeyStore keyStore = KeyStore.getInstance("PKCS12"); // ?PKCS12? FileInputStream instream = new FileInputStream(pkcFile); try { // PKCS12?(ID) keyStore.load(instream, storeId.toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, storeId.toCharArray()).build(); // Allow TLSv1 protocol only // TLS SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); // httpclientSSLSocketFactory CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpPost post = new HttpPost(url); StringEntity s = new StringEntity(params, "utf-8"); if (StringUtils.isBlank(contentType)) { s.setContentType("application/xml"); } s.setContentType(contentType); post.setEntity(s); HttpResponse res = httpclient.execute(post); HttpEntity entity = res.getEntity(); text = EntityUtils.toString(entity, "utf-8"); } finally { httpclient.close(); } return text; }