inputstream

Reading lines from an InputStream without buffering

别说谁变了你拦得住时间么 提交于 2020-01-20 06:43:07
问题 Does Java have a simple method to read a line from an InputStream without buffering? BufferedReader is not suitable for my needs because I need to transfer both text and binary data through the same connection repeatedly and buffering just gets in the way. 回答1: Eventually did it manually directly reading byte after byte from the InputStream without wrapping the InputStream. Everything I tried, like Scanner and InputStreamReader, reads ahead (buffers) the input :( I guess I missed a some cases

How to download a pdf file programmatically from a webpage with .html extension?

做~自己de王妃 提交于 2020-01-19 14:58:48
问题 I have reviewed ALL similar questions (not only this!) on this forum and have tried ALL of those methods however still was not able to programmatically download a test file: http://pdfobject.com/markup/examples/full-browser-window.html The following is the direct link to the test file that i am trying to download. This is a test pdf file with an open access, so anybody can use it to test a download method. How can I download this particular file so that it has a pdf extension? 回答1: For

The most efficient way to show the local image in android

送分小仙女□ 提交于 2020-01-17 03:04:11
问题 I am currently work on a magazine like apps. Since there is an option to zoom in(150%, 200%, 250% of original source) , I would prefer not to scale down the image. However , the app will force restart when I try to decode the image because of the out of memory. Are there any suggestion to fix that? The image are local (SD card) , can be retrieve in any approach, but eventually need to be a bitmap as I use something like cavans.drawbitmap to display it. I tried, input stream-> bytes , input

The most efficient way to show the local image in android

可紊 提交于 2020-01-17 03:03:07
问题 I am currently work on a magazine like apps. Since there is an option to zoom in(150%, 200%, 250% of original source) , I would prefer not to scale down the image. However , the app will force restart when I try to decode the image because of the out of memory. Are there any suggestion to fix that? The image are local (SD card) , can be retrieve in any approach, but eventually need to be a bitmap as I use something like cavans.drawbitmap to display it. I tried, input stream-> bytes , input

Logging InputStream

给你一囗甜甜゛ 提交于 2020-01-15 12:29:05
问题 I create an InputStream class, that extends CiphetInputStream. I want to log all data from my InputStream (that i use as input in parser further) so i done following: public class MyInputStream extends CipherInputStream { private OutputStream logStream = new ByteArrayOutputStream(); ..... @Override public int read() throws IOException { int read = super.read(); logStream.write(read); return read; } @Override public int read(byte[] b, int off, int len) throws IOException { int read = super

Interrupting BitmapFactory.decodeStream

◇◆丶佛笑我妖孽 提交于 2020-01-15 11:39:13
问题 Let's assume we have a worker thread which calls BitmapFactory.decodeStream with some connection stream, like this: Bitmap bitmap = BitmapFactory.decodeStream(new URL(imgUrl).openConnection().getInputStream(), null, someUnrelatedOptions); Now we need to terminate this thread immedietely in order to reclaim any memory that BitmapFactory has allocated. We can't wait for it to finish for too long, as the memory is required by UI thread. The example is simplified, so let's don't go into details

Can't read in HTML content from valid URL

馋奶兔 提交于 2020-01-15 09:39:07
问题 I am trying out a simple program for reading the HTML content from a given URL. The URL I am trying in this case doesn't require any cookie/username/password, but still I am getting a io.IOException: Server returned HTTP response code: 403 error. Can anyone tell me what am I doing wrong here? (I know there are similar question in SO, but they didn't help): import java.net.*; import java.io.*; import java.net.MalformedURLException; import java.io.IOException; public class urlcont { public

Dealing with getResourceAsStream for outside file

核能气质少年 提交于 2020-01-15 08:31:09
问题 I'm having a problem with getResourceAsStream method - it returns null because of wrong directory. The problem is that I do not have an idea how to define the dir. My project structure looks like that Project #src #com.package #ExampleClass.java #dll #MyFile.dll When I have InputStream in = this.getClass().getResourceAsStream("../dll/" + "MyFile.dll"); It returns null. Do anyone have an idea how to deal with this problem and how the path schould be defined? 回答1: If this is ExampleClass in com

read of Inputstream non stop when internet connection lost

佐手、 提交于 2020-01-14 18:48:45
问题 I'a using a asynctask to download file. It works normally until i turn off wifi connection (there are no other internet connection) of my android, download dialog still and no changes. When i check by log, i discover that function read() of inputstream is non stop. So how to check this case? here is my code: URL url = new URL(this.url); URLConnection connection = url.openConnection(); connection.setReadTimeout(1000); connection.connect(); // this will be useful so that you can show a typical

Any util class/method to take a large String and return an InputStream?

社会主义新天地 提交于 2020-01-14 12:55:11
问题 I am looking for some util class/method to take a large String and return an InputStream . If the String is small, I can just do: InputStream is = new ByteArrayInputStream(str.getBytes(<charset>)); But when the String is large(1MB, 10MB or more), a byte array 1 to 2 times(or more?) as large as my String is allocated on the spot. (And since you won't know how many bytes to allocate exactly before all the encoding is done, I think there must be other arrays/buffers allocated before the final