List of utility methods to do InputStream Save
void | dumpToFile(File file, InputStream inputStream) Dump an input stream to a file, throws exceptions that you will likely want to handle. if (!file.exists()) { file.createNewFile(); FileOutputStream fios = new FileOutputStream(file); byte[] buffer = new byte[1024]; int len = inputStream.read(buffer); while (len != -1) { fios.write(buffer, 0, len); ... |
boolean | saveFile(InputStream in, String fileName) save File File outFile = new File(fileName); try { FileOutputStream out = new FileOutputStream(outFile); byte[] temp = new byte[11024]; int length = -1; while ((length = in.read(temp)) > 0) out.write(temp, 0, length); out.flush(); ... |
void | saveToLocal(InputStream in, String filePath) save To Local try { File file = new File(filePath); if (!file.exists() && !file.isDirectory()) { file.createNewFile(); DataOutputStream out = new DataOutputStream( new FileOutputStream(new File(file.getAbsolutePath()))); byte[] dataByte = new byte[in.available()]; ... |
void | writerFromInputStream(InputStream stream, String path, String fileName) writer From Input Stream FileOutputStream fs = null; try { File file = new File(path); if (!file.exists()) { file.mkdirs(); fs = new FileOutputStream(path + File.separator + fileName); byte[] buffer = new byte[1024 * 1024]; ... |
void | writeFile(File outputFile, InputStream inputStream) write File try { OutputStream out = new FileOutputStream(outputFile); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { out.write(bytes, 0, read); out.flush(); ... |
boolean | saveFile(Context context, String fileName, InputStream inputStream) save File File cacheDir = context.getCacheDir(); File outputFile = new File(cacheDir, fileName); writeFile(outputFile, inputStream); return true; |
Boolean | writeXmlToTempFile(InputStream xmlStream, String filePath, String closingTag) write Xml To Temp File Boolean downloadSuccessful = false; File tempFile = new File(filePath); FileOutputStream stream = new FileOutputStream(tempFile); BufferedReader reader = new BufferedReader(new InputStreamReader( xmlStream)); String line; while ((line = reader.readLine()) != null) { stream.write(line.getBytes()); ... |
String | writeToString(InputStream stream) write To String StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new InputStreamReader( stream, "utf-8")); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); ... |
void | saveInputStreamAsFile(InputStream inputStream, File target) save Input Stream As File final FileOutputStream fos = new FileOutputStream(target); writeFile(inputStream, fos); closeIOStream(fos); closeIOStream(inputStream); |
void | saveStream(InputStream is, String savePath) save Stream FileOutputStream output = new FileOutputStream(savePath); int readlen; byte[] buf = new byte[BUFF_SIZE]; while ((readlen = is.read(buf)) > 0) output.write(buf, 0, readlen); output.close(); is.close(); |