inputstream

Java I/O - Reuse InputStream Object

放肆的年华 提交于 2019-12-22 07:50:18
问题 Is there anyway to reuse an inputStream by changing its content? (Without new statement). For instance, I was able to something very close to my requirement, but not enough In the following code I am using a SequenceInputStream , and everytime I am adding a new InputStream to that sequence. But I would like to do the same thing by using the same inputStream (I don't care which implementation of InputStream ). I thought about mark() / reset() APIs, but i still need to change the content to be

Apache HttpClient in Java, instream.toString = org.apache.http.conn.EofSensorInputStream

旧街凉风 提交于 2019-12-22 06:55:47
问题 I am GETting a page with Apache HttpClient and I want to store the server reply's http body into a string so I can then manipulate this string and print it to the console. Unfortunately when running this method I get this message back: 17:52:01,862 INFO Driver:53 - fetchPage STARTING 17:52:07,580 INFO Driver:73 - fetchPage ENDING, took 5716 org.apache.http.conn.EofSensorInputStream@5e0eb724 The fetchPage Class: public String fetchPage(String part){ log.info("fetchPage STARTING"); long start =

How should an InputStream and an OutputStream be closed?

梦想的初衷 提交于 2019-12-22 06:48:16
问题 I'm using the following code to close an InputStream and an OutputStream from a connection to a server: try { if (mInputStream != null) { mInputStream.close(); mInputStream = null; } if (mOutputStream != null) { mOutputStream.close(); mOutputStream = null; } } catch (IOException e) { e.printStackTrace(); } However, the streams are not closing, they are still alive. If I connect again there are two different InputStreams. No exception is being caught in the catch section. What am I doing wrong

Java process.getInputStream() has nothing to read, deadlocks child

霸气de小男生 提交于 2019-12-22 04:04:24
问题 I am having an issue with some process wrapping, and it's only occurring in Windows XP. This code works perfectly in Windows 7. I'm really stumped as to why the streams are empty in XP. I've also tried using the String[] version of Process.Exec() and it made no difference. I am using the following class to read from the process' STDOUT and STDERR (an instance for each stream): import java.util.*; import java.io.*; public class ThreadedStreamReader extends Thread{ InputStream in; Queue

InputStream from relative path

一个人想着一个人 提交于 2019-12-22 01:24:31
问题 I have a relative file path (for example "/res/example.xls") and I would like to get an InputStream Object of that file from that path. I checked the JavaDoc and did not find a constructor or method to get such an InputStream from a path/ Anyone has any idea? Please let me know! Thank you 回答1: Use FileInputStream: InputStream is = new FileInputStream("/res/example.xls"); But never read from raw file input stream as this is terribly slow. Wrap it with buffering decorator first: new

Do I have to close FileInputStream?

隐身守侯 提交于 2019-12-22 01:23:50
问题 I am working as a trainee in Test Automation. I am working with creating Junit code with Eclipse and run using Eclipse. In that I am retriving the datas from excel sheet using FileInputStream function. FileInputStream fi=new FileInputStream("c:\\search.xls"); Workbook w=Workbook.getWorkbook(fi); Sheet s=w.getSheet(0); Is it necessary to close the Inputstream function? If it so please guide me with some codings. 回答1: Yes, you need to close the inputstream if you want your system resources

How to calculate microphone audio input power in decibel unit

你离开我真会死。 提交于 2019-12-22 01:20:34
问题 Please help me calculate decibels from phone microphone. The microphone has a getMaxAmplitude() function. How I can I use it to calculate decibels? I read in some forums that the decibel calculation formula is power_db = 20 * log10(amplitude / reference_amplitude) . But I don't understand how to find the reference_amplitude . 回答1: Decibels are a unit widely used to define some quantity relative to something else. There are a number of different types of decibel measurements, depending on what

Do I have to close FileInputStream?

天大地大妈咪最大 提交于 2019-12-22 01:14:28
问题 I am working as a trainee in Test Automation. I am working with creating Junit code with Eclipse and run using Eclipse. In that I am retriving the datas from excel sheet using FileInputStream function. FileInputStream fi=new FileInputStream("c:\\search.xls"); Workbook w=Workbook.getWorkbook(fi); Sheet s=w.getSheet(0); Is it necessary to close the Inputstream function? If it so please guide me with some codings. 回答1: Yes, you need to close the inputstream if you want your system resources

getimagesize() on stream instead of string

会有一股神秘感。 提交于 2019-12-21 16:58:11
问题 I'm using Valum's file uploader to upload images with AJAX. This script submits the file to my server in a way that I don't fully understand, so it's probably best to explain by showing my server-side code: $pathToFile = $path . $filename; //Here I get a file not found error, because the file is not yet at this address getimagesize($pathToFile); $input = fopen('php://input', 'r'); $temp = tmpfile(); $realSize = stream_copy_to_stream($input, $temp); //Here I get a string expected, resource

How can I access a txt file in a jar with FileInputStream?

≡放荡痞女 提交于 2019-12-21 12:51:08
问题 I am aware of the getResourceAsStream() method but there is an issue with the parser that reads the file, the whole structure was implemented to expect a FileInputStream() and the getResourceAsStream() returns an input stream which cannot be casted. Is there any easy "fix" for this situation? 回答1: A resource contained within a JAR file is not itself a file, and cannot be read using a FileInputStream . If you have code that absolutely requires a FileInputStream , then you'll need to extract