List of utility methods to do InputStream Create
InputStream | asInputStream(byte[] bytes) as Input Stream return new ByteArrayInputStream(bytes); |
InputStream | asInputStream(File file) Return an input stream to the file. return new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE); |
InputStream | asInputStream(Object content) Returns an input stream for the specified content. if (content instanceof byte[]) { return new ByteArrayInputStream((byte[]) content); } else if (content instanceof File) { return new FileInputStream((File) content); } else { return new ByteArrayInputStream(content.toString().getBytes("UTF-8")); |
InputStream | asInputStream(String str) as Input Stream try { return new ByteArrayInputStream(str.getBytes(CHARSET)); } catch (UnsupportedEncodingException e) { assert false; return null; |
InputStream | getInputStream(File f) Gets the input stream for a given file (for tar archives) InputStream is = new FileInputStream(f); try { return new GZIPInputStream(is); } catch (IOException e) { return new FileInputStream(f); |
InputStream | getInputStream(File jarFile, String fileName) get Input Stream ZipFile zipFile = new ZipFile(jarFile); ZipEntry zipEntry = zipFile.getEntry(fileName); return zipFile.getInputStream(zipEntry); |
InputStream | getInputStream(File tarFile) If tarFile's extension is simply tar, then returns a new FileInputStream. String name = tarFile.getName().toLowerCase(); if (name.endsWith(".tar")) { return new FileInputStream(tarFile); } else if (name.endsWith(".tar.gz") || name.endsWith(".tgz")) { return new GZIPInputStream(new FileInputStream(tarFile)); } else { throw new IllegalArgumentException( "tarFile = " + tarFile.getPath() + " has an invalid extension for a tar or tar/gzip file"); ... |
InputStream | getInputStream(File tarFile) get Input Stream return (new FileInputStream(tarFile)); |
InputStream | getInputStream(File TheFile) get Input Stream validateReadableFile(TheFile); try { InputStream in = new FileInputStream(TheFile); return (in); } catch (FileNotFoundException ex) { String Fullpath = TheFile.getAbsolutePath(); throw new IllegalStateException( "Requested File '" + Fullpath + "' does not exist - but has been tested - HUH???"); ... |
InputStream | getInputStream(FileInputStream fileInput) get Input Stream ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024 * 4]; int n = -1; InputStream inputStream = null; try { while ((n = fileInput.read(buffer)) != -1) { baos.write(buffer, 0, n); byte[] byteArray = baos.toByteArray(); inputStream = new ByteArrayInputStream(byteArray); return inputStream; } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); |