List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:Main.java
public static Bitmap readBitmapFromPath(Context context, Uri path) throws Exception { InputStream stream = context.getContentResolver().openInputStream(path); Bitmap bitmap = BitmapFactory.decodeStream(stream); if (stream != null) { stream.close(); }/*from www . java 2 s .com*/ return bitmap; }
From source file:de.shadowhunt.subversion.internal.ResourcePropertyUtils.java
static InputStream escapedInputStream(final InputStream inputStream) throws IOException { final String rawData = IOUtils.toString(inputStream, UTF8); inputStream.close(); final Matcher matcher = PATTERN.matcher(rawData); final String escapedData = matcher.replaceAll("<$1$2$3:$4" + MARKER + "$5$6$7>"); return IOUtils.toInputStream(escapedData, UTF8); }
From source file:Main.java
public static JSONObject loadJsonFile(Context context, String fileName) throws IOException, JSONException { InputStream is = context.getAssets().open(fileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer);/*from w w w . jav a 2 s. c o m*/ is.close(); String jsonString = new String(buffer); return new JSONObject(jsonString); }
From source file:com.xpfriend.fixture.runner.example.ExampleJob.java
/** * db.properties ?????//w w w . j av a2 s. c o m * @return ? */ private static Properties getProperties() throws IOException { Properties props = new Properties(); InputStream is = ClassLoader.getSystemResourceAsStream("db.properties"); try { props.load(is); } finally { is.close(); } return props; }
From source file:Main.java
public static Document toDocument(InputStream in) throws Exception { try {//from ww w. jav a2s .com return builder.get().parse(in); } finally { in.close(); } }
From source file:Main.java
public static Schema getSchemaFromResource(String... files) throws SAXException, FileNotFoundException { InputStream[] inputStreams = new InputStream[files.length]; Schema schema = null;// w ww. j a va 2 s.c o m try { for (int i = 0; i < files.length; i++) { inputStreams[i] = loadResourceInputStream(files[i]); } schema = getSchema(inputStreams); } finally { for (InputStream is : inputStreams) { try { if (is != null) { is.close(); } } catch (Exception ex) { } } } return schema; }
From source file:org.brekka.stillingar.spring.version.ApplicationVersionFromMaven.java
private static void closeQuietly(InputStream is) { try {//from w w w .j av a 2 s.com is.close(); } catch (IOException e) { } }
From source file:Main.java
public static byte[] loadAsset(Context context, String asset) { byte[] buffer = null; try {/* w w w . j a v a 2s .co m*/ InputStream is = context.getAssets().open(asset); int size = is.available(); buffer = new byte[size]; is.read(buffer); is.close(); } catch (IOException e) { Log.e(TAG, "Failed to load asset " + asset + ": " + e); } return buffer; }
From source file:com.alexholmes.hadooputils.io.FileUtils.java
/** * Read the contents of the supplied file into a list. * * @param fs a Hadoop file system/*from w w w . j a v a2 s . co m*/ * @param p the file path * @return array of lines in the file * @throws java.io.IOException if something goes wrong */ public static List<String> readLines(final FileSystem fs, final Path p) throws IOException { InputStream stream = fs.open(p); try { return IOUtils.readLines(stream); } finally { stream.close(); } }
From source file:com.aurel.track.exchange.docx.exporter.LaTeXExportBL.java
/** * Serializes the docx content into the response's output stream * @param response/*from w w w .j a v a 2s . co m*/ * @param wordMLPackage * @return */ static String prepareReportResponse(HttpServletResponse response, TWorkItemBean workItem, ReportBeans reportBeans, TPersonBean user, Locale locale, String templateDir, String templateFile) { ReportBeansToLaTeXConverter rl = new ReportBeansToLaTeXConverter(); File pdf = rl.generatePdf(workItem, reportBeans.getItems(), true, locale, user, "", "", false, new File(templateFile), new File(templateDir)); OutputStream outputStream = null; try { outputStream = response.getOutputStream(); InputStream is = new FileInputStream(pdf); IOUtils.copy(is, outputStream); is.close(); } catch (FileNotFoundException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { LOGGER.error("Getting the output stream failed with " + e.getMessage()); LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } return null; }