inputstream

If it safe to return an InputStream from try-with-resource [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-05 07:55:38
问题 This question already has answers here : Try-with-resources and return statements in java (4 answers) Closed 5 years ago . Is it safe to return an input stream from a try-with-resource statement to handle the closing of the stream once the caller has consumed it? public static InputStream example() throws IOException { ... try (InputStream is = ...) { return is; } } 回答1: It's safe, but it will be closed, so I don't think it is particularly useful... (You can't reopen a closed stream.) See

If it safe to return an InputStream from try-with-resource [duplicate]

核能气质少年 提交于 2021-02-05 07:55:10
问题 This question already has answers here : Try-with-resources and return statements in java (4 answers) Closed 5 years ago . Is it safe to return an input stream from a try-with-resource statement to handle the closing of the stream once the caller has consumed it? public static InputStream example() throws IOException { ... try (InputStream is = ...) { return is; } } 回答1: It's safe, but it will be closed, so I don't think it is particularly useful... (You can't reopen a closed stream.) See

Cloning/Multiple reading an Input Stream from an HttpResponse

若如初见. 提交于 2021-01-29 07:21:14
问题 I have an HttpResponse containing some data (json/xml, which can contain a large amount of data). I am using a function that reads and uses an input stream with this data (which is closed, and cannot be changed either than maybe accepting a string instead of an inputstream), and a different function that validates the data (general validation, not related to the actual usage which is a part I can't touch). I would like to do something like this: HttpResponse response = getTheResponse();

How to stop a sound (while its playing) from another method

醉酒当歌 提交于 2021-01-29 06:29:10
问题 I have some music playing in my program. I want it to switch music depending on certain actions etc. The problem is I have my music begin playing from one method and I am trying to stop it from another method or action event. The other method isnt able to find my clip object because it is not public. Is it possible to make this clip object public for my whole class? I tried making another class just for music. Could someone guide me? Thanks, public void playsound(String filepath){ try {

How to stop a sound (while its playing) from another method

筅森魡賤 提交于 2021-01-29 06:20:49
问题 I have some music playing in my program. I want it to switch music depending on certain actions etc. The problem is I have my music begin playing from one method and I am trying to stop it from another method or action event. The other method isnt able to find my clip object because it is not public. Is it possible to make this clip object public for my whole class? I tried making another class just for music. Could someone guide me? Thanks, public void playsound(String filepath){ try {

Why does my “content://” URI return a null InputStream, even though I can read from the ZipResourceFile object?

ε祈祈猫儿з 提交于 2021-01-29 05:10:40
问题 I'm setting up Google's APEZProvider to read .PNGs (compressed) and .MP3s (not compressed) from an APK Expansion zip file. File retrieval works just fine if I avoid the URI, and stick to "getAPKExpansionZipFile()" But when I try to retrieve my files using the "content://" API, I am getting a null InputStream. (I need the URI to satisfy the APIs of media players.) This is for an Android app targeting API 26. In the past I was able to get the content provider working. But I've broken something.

Why does my “content://” URI return a null InputStream, even though I can read from the ZipResourceFile object?

只谈情不闲聊 提交于 2021-01-29 05:10:19
问题 I'm setting up Google's APEZProvider to read .PNGs (compressed) and .MP3s (not compressed) from an APK Expansion zip file. File retrieval works just fine if I avoid the URI, and stick to "getAPKExpansionZipFile()" But when I try to retrieve my files using the "content://" API, I am getting a null InputStream. (I need the URI to satisfy the APIs of media players.) This is for an Android app targeting API 26. In the past I was able to get the content provider working. But I've broken something.

Is inline created InputStream closed automatically by GC?

ぃ、小莉子 提交于 2021-01-28 07:35:31
问题 I've found several similar questions, but I still can't find the answer to my question. I know that it is enough to close the outer stream and it will close inner stream which is created in line. BufferedInputStream br = new BufferedInputStream(new FileInputStream(file)); br.close(); Consider next example Properties props = new Properties(); props.load(new FileInputStream(configPath)); Should the FileInputStream be assigned to a variable and then closed explicitly (or with try-with-resource

Angular doesn't download a file from a stream ( StreamingResponseBody )

▼魔方 西西 提交于 2021-01-24 02:52:39
问题 I'm using angular to download big files, for the backend I'm using spring boot, here's the code of the end point: @RequestMapping(value = "/download", method = RequestMethod.GET) public StreamingResponseBody download(@PathVariable String path) throws IOException { final InputStream file =azureDataLakeStoreService.readFile(path); return (os) -> { readAndWrite(file , os); }; } private void readAndWrite(final InputStream is, OutputStream os) throws IOException { byte[] data = new byte[2048]; int

Stream upload 'POST' in Spring WebClient

亡梦爱人 提交于 2021-01-04 03:24:31
问题 I am uploading streams of (raw bytes) data using HTTP posts using WebClient: final byte[] rawData = IOUtils.toByteArray(sourceInputStream); webClient.post() .uri(uri) .contentType(MediaType.APPLICATION_OCTET_STREAM) .bodyValue(rawData) .exchange()... I am concerned there is a potentially a lot of memory used given sometimes these objects can be quite big (~200Mb) so would like to read directly from the InputStream and upload as a stream. I tried: bodyValue(BodyInserters.fromResource(new