List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:Main.java
public static void copyFile(FileInputStream src, FileOutputStream dst) throws Throwable { byte[] buf = new byte[65536]; for (int len = src.read(buf); len > 0; len = src.read(buf)) { dst.write(buf, 0, len);//w w w. ja v a2 s .c o m } src.close(); dst.close(); }
From source file:com.hy.utils.pay.wx.ClientCustomSSL.java
public static void test() throws Exception { KeyStore keyStore = KeyStore.getInstance("PKCS12"); FileInputStream instream = new FileInputStream(new File("D:/10016225.p12")); try {/*from w w w . j av a 2 s . c o m*/ keyStore.load(instream, "10016225".toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "10016225".toCharArray()).build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpGet httpget = new HttpGet("https://api.mch.weixin.qq.com/secapi/pay/refund"); System.out.println("executing request" + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent())); String text; while ((text = bufferedReader.readLine()) != null) { System.out.println(text); } } EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.cisco.dbds.utils.configfilehandler.ConfigFileHandler.java
/** * Load config file./*w ww .ja v a 2 s . co m*/ * * @param filepath the filepath * @throws IOException Signals that an I/O exception has occurred. */ public static void loadConfigFile(String filepath) throws IOException { System.out.println("loadConfigFile inisde"); //File dir = new File("src/it/resources"); File dir = new File(filepath); String[] extensions = new String[] { "properties" }; System.out.println("Getting all .properties files in " + dir.getCanonicalPath() + " including those in subdirectories"); List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true); for (File file : files) { System.out.println("file: " + file.getCanonicalPath()); FileInputStream fn = new FileInputStream(file.getCanonicalPath()); setSystemvariable(fn); fn.close(); } }
From source file:Main.java
public static Document parse(File file) throws IOException, ParserConfigurationException, SAXException { FileInputStream inputStream = new FileInputStream(file); try {/*from w ww. ja v a2s . c om*/ return parse(inputStream); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { } } } }
From source file:Main.java
public static String getSHA(File f, int length) { if (!f.isFile() || length <= 0) { return null; }/*from w w w.j a v a 2 s. co m*/ FileInputStream f1; byte[] buf = new byte[length]; int n; try { f1 = new FileInputStream(f); n = f1.read(buf, 0, length); f1.close(); } catch (IOException e) { return null; } return getSHA(buf); }
From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java
public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException { if (!logFile.exists()) { throw new FileNotFoundException(); }//from www . ja va 2 s .c o m File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip"); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); zipOutputStream.setEncoding(ZIP_ENCODING); ArchiveEntry archiveEntry = newArchive(logFile); zipOutputStream.putArchiveEntry(archiveEntry); FileInputStream logFileInput = new FileInputStream(logFile); IOUtils.copyLarge(logFileInput, zipOutputStream); logFileInput.close(); zipOutputStream.closeArchiveEntry(); zipOutputStream.close(); FileInputStream tempFileInput = new FileInputStream(tempFile); IOUtils.copyLarge(tempFileInput, outputStream); tempFileInput.close(); FileUtils.deleteQuietly(tempFile); }
From source file:com.ibm.ids.example.ShowResult.java
public static String getVulnerableSource(String file) throws java.io.IOException, java.io.FileNotFoundException { FileInputStream fis = new FileInputStream(file); byte[] buf = new byte[100]; fis.read(buf);/*from w ww . ja v a 2 s .com*/ String ret = new String(buf); fis.close(); return ret; }
From source file:Main.java
public static boolean copyFile(File fin, File fout) { FileInputStream in = null; FileOutputStream out = null;/*from www .j a v a2s.c o m*/ try { in = new FileInputStream(fin); out = new FileOutputStream(fout); copyFile(in, out); in.close(); out.close(); } catch (IOException e) { if (in != null) try { in.close(); } catch (IOException e2) { } if (out != null) try { out.close(); } catch (IOException e3) { } return false; } return true; }
From source file:Main.java
public static String readTextFromSDcard(String fileName) { File file = new File(fileName); if (!file.exists()) { return null; }/*w w w.j av a 2s . c om*/ try { FileInputStream fileInputStream = new FileInputStream(file); int availableLength = fileInputStream.available(); byte[] buffer = new byte[availableLength]; fileInputStream.read(buffer); fileInputStream.close(); return new String(buffer, "UTF-8"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:eu.scape_project.tool.toolwrapper.data.tool_spec.utils.Utils.java
/** * Method that creates a {@link Tool} instance from the provided toolspec * file, validating it against toolspec XML Schema * /* w w w . j a v a 2s . c o m*/ * @param toolspecFilePath * path to the toolspec file */ @SuppressWarnings("resource") public static Tool createTool(String toolspecFilePath) throws JAXBException, IOException, SAXException { final FileInputStream stream = new FileInputStream(new File(toolspecFilePath)); try { return fromInputStream(stream); } finally { stream.close(); } }