inputstream

Memory issues with InputStream in Java

这一生的挚爱 提交于 2019-12-20 03:21:48
问题 I need to read a file into an array of Bytes.The entire file needs to be read into the array. The problem is I am getting an OutOfMemory Error since the file size is too large. Increasing -XmX does not seem to have any effect. Here is the code snippet : InputStream in = new FileInputStream(file); long length = file.length(); byte[] out = new byte[(int)length]; // Process the byte array The problem occurs during the byte array instantion. Is there a less memory intensive workaround to this

C# equivalent of file_get_contents (PHP)

余生长醉 提交于 2019-12-20 03:10:29
问题 As a follow-up to (OAuthException) (#15) The method you are calling must be called with an app secret signed session I want to know what is the equivalent of file_get_contents(). I tried the following but I got illegal characters in path error. public ActionResult About() { var fb = new FacebookWebClient(FacebookWebContext.Current); var tokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + FacebookWebContext.Current.Settings.AppId + "&client_secret=" + FacebookWebContext

skipws flag set when opening an input file stream in binary mode

爷,独闯天下 提交于 2019-12-20 02:43:06
问题 I know the extraction operator should not be used on an input stream opened in binary mode, but the member function read should be used instead. std::ifstream ifs("file.bin", std::ios::in | std::ios::binary); char c; ifs >> c; // Should not be used ifs.read(&c, 1); // OK But it can be done anyway. So my question is what is the rationale for not unsetting the skipws flag on input file streams when opened in binary mode? 回答1: "Binary" mode, as controlled by std::ios_base::binary is only for

How to handle IO streams in Spring MVC

[亡魂溺海] 提交于 2019-12-20 01:35:00
问题 I have a method which returns ResponseEntity(InputStreamResource) . In this method, I'm getting InputStream from a file based on the filename input and then sending InputStreamResource as a response. Code snippet InputStream inputStream = ...; ResponseEntity<InputStreamResource> response = new ResponseEntity<InputStreamResource>(new InputStreamResource(inputStream), headers, HttpStatus.OK); return response; Here do I need to close inputStream object? If I do so, I'm getting

Get filename from an inputstream (Java)

我们两清 提交于 2019-12-19 19:38:28
问题 if I have this code, how could I keep the filename of the original file or reassign it to the new one?: InputStream input= assetInfo.openStream(); File t = new File(""); OutputStream out = new FileOutputStream(t); int read=0; byte[] bytes = new byte[1024]; while((read = input.read(bytes))!= -1){ out.write(bytes, 0, read); } 回答1: An input stream can be created to read from a file or from any other source of data. Therefore it makes no sense to have a filename attached to an input stream. Look

JarEntry.getSize() is returning -1 when the jar files is opened as InputStream from URL

醉酒当歌 提交于 2019-12-19 18:54:47
问题 I am trying to read file from the JarInputStream and the size of file is returning -1. I am accessing Jar file from the URL as a inputStream. URLConnection con = url.openConnection(); JarInputStream jis = new JarInputStream(con.getInputStream()); JarEntry je = null; while ((je = jis.getNextJarEntry()) != null) { htSizes.put(je.getName(), new Integer((int) je.getSize())); if (je.isDirectory()) { continue; } int size = (int) je.getSize(); // -1 means unknown size. if (size == -1) { size = (

JarEntry.getSize() is returning -1 when the jar files is opened as InputStream from URL

巧了我就是萌 提交于 2019-12-19 18:51:54
问题 I am trying to read file from the JarInputStream and the size of file is returning -1. I am accessing Jar file from the URL as a inputStream. URLConnection con = url.openConnection(); JarInputStream jis = new JarInputStream(con.getInputStream()); JarEntry je = null; while ((je = jis.getNextJarEntry()) != null) { htSizes.put(je.getName(), new Integer((int) je.getSize())); if (je.isDirectory()) { continue; } int size = (int) je.getSize(); // -1 means unknown size. if (size == -1) { size = (

JarEntry.getSize() is returning -1 when the jar files is opened as InputStream from URL

醉酒当歌 提交于 2019-12-19 18:51:06
问题 I am trying to read file from the JarInputStream and the size of file is returning -1. I am accessing Jar file from the URL as a inputStream. URLConnection con = url.openConnection(); JarInputStream jis = new JarInputStream(con.getInputStream()); JarEntry je = null; while ((je = jis.getNextJarEntry()) != null) { htSizes.put(je.getName(), new Integer((int) je.getSize())); if (je.isDirectory()) { continue; } int size = (int) je.getSize(); // -1 means unknown size. if (size == -1) { size = (

Java ProgressMonitorInputStream using existing JProgressBar

这一生的挚爱 提交于 2019-12-19 10:26:56
问题 I'm just playing about with Java's ProgressMonitorInputStream to monitor data as it flows through a BufferedInputStream. Here is the code I'm currently trying: InputStream in = new BufferedInputStream( new ProgressMonitorInputStream( new JFrame(),"Scanning",new FileInputStream(dir.getSearchInputFile()))); This works perfectly fine, and pops up a new JFrame window with a progress bar that displays the progress of the input stream. Is there anyway of getting the ProgressMonitorInputstream to

How to programmatically limit the download speed?

南笙酒味 提交于 2019-12-19 07:27:12
问题 I use the following code to limit the download speed of a file in java: package org; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; class MainClass { public static void main(String[] args) { download("https://speed.hetzner.de/100MB.bin"); } public static void download(String link) { try { URL url = new URL(link); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setConnectTimeout(5000); con.setReadTimeout