inputstream

How to convert BufferedImage to InputStream? [duplicate]

◇◆丶佛笑我妖孽 提交于 2020-01-10 01:15:11
问题 This question already has answers here : How to get an InputStream from a BufferedImage? (3 answers) Closed 2 months ago . I am uploading images using servlet. To perform resize operations i am converting InputStream to BufferedImage. Now i want to save it in mongoDB. Since, i am new to mongoDB as far as i know, GridFS takes InputStream. So, is there any way to convert BufferedImage to InputStream? 回答1: You need to save the BufferedImage to a ByteArrayOutputStream using the ImageIO class,

Android:“Unexpected end of stream” exception downloading large files

邮差的信 提交于 2020-01-09 10:29:31
问题 I am building an Android Application and I need to download a file from a url, which is 33 MB large. Here the download task: try { int MAX_BUFFER_SIZE = 4096; URL mUrl = new URL(params[0]); HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection(); connection.setRequestMethod("GET"); long length = connection.getContentLength(), downloaded = 0; int read; byte [] buffer = new byte[(((int)length) > MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE : (int)length]; String filename = getFilename

Wrapping a ByteBuffer with an InputStream

自古美人都是妖i 提交于 2020-01-09 04:38:05
问题 I have a method that takes an InputStream and reads data from it. I would like to use this method with a ByteBuffer also. Is there a way to wrap a ByteBuffer so it can be accessed as a stream? 回答1: Nothing in the JDK, but there are lots of implementations out there, google for ByteBufferInputStream. Basically they wrap one or more ByteBuffers and keep track of an index into them that records how much has already been read. Something like this comes up a lot, but apparently is buggy, see @Mike

java.io.IOException: unexpected end of stream on Connection in android

我与影子孤独终老i 提交于 2020-01-09 03:39:04
问题 I have web service URL, it working fine. It gives the JSON data. When I use HttpURLConnection , InputStream , I am getting an error. like java.io.IOException: unexpected end of stream on Connection{comenius-api.sabacloud.com:443, proxy=DIRECT hostAddress=12.130.57.1 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 protocol=http/1.1} (recycle count=0) try{ URL url = new URL("https://comenius-api.sabacloud.com/v1/people/username="+username+":(internalWorkHistory)?type=internal&SabaCertificate=

Convert BufferedInputStream into image [duplicate]

蓝咒 提交于 2020-01-08 16:59:28
问题 This question already has an answer here : ImageIO.read returns null on byte array (1 answer) Closed 6 years ago . Im having trouble turning my blob into a buffered image so I can use it. I'm getting a blob (jpg image) back from my database I uploaded using inputstream. In my database it is stored as BufferedInputStream I notice. I get the blob just fine, its a bunch of weird symbols and says its a jpg so the image has to be fine. Can anyone spot what I'm doing wrong? Maybe im converting it

copying files in android with input/output stream: the good and the bad way

試著忘記壹切 提交于 2020-01-07 09:49:19
问题 i have made this two routines to copy files using inputstream and outpustream. they are quite the same however the second one rise ArrayIndexOutOfBoundsException while the first one works flawlessly and i don't know why: public void CopyStream(long size, InputStream is, OutputStream os) { final int buffer_size = 4096; byte[] bytes = new byte[buffer_size]; try { int count,prog=0; while ((count = is.read(bytes)) != -1) { os.write(bytes, 0, count); //write buffer prog = prog + count;

How to avoid EOFException for an empty HTTP response from HttpURLConnection?

不想你离开。 提交于 2020-01-06 15:41:31
问题 I'm sending an HTTP request to a server which legitimately returns a blank response with HTTP response code = 200 (OK). But this causes the marked line below to throw an EOFException : InputStream responseStream = httpURLConnection.getInputStream(); final String contentEncoding = this.connection.getContentEncoding(); if ("gzip".equalsIgnoreCase(contentEncoding)) { responseStream = new GZIPInputStream(responseStream); // throws EOFException } There may be an obvious way to prevent this but I

Why InputStream is stopping my application?

随声附和 提交于 2020-01-06 12:38:12
问题 I have an Android App that talks with a Java Server between socket connection. When server is running, there's no problem. I send something from Android and server answer. I get response and put it in Toast. Looks great! But if i stop running server, Android stay waiting for answer and all application stop working. Strange is the fact that application in running inside a thread, so i think its not supposed to happen. I'd like to know if is there some way to avoid it to crash application and

How can I read different groups of data on the same InputStream, using different types of InputStreams for each of them?

坚强是说给别人听的谎言 提交于 2020-01-06 08:43:30
问题 I needed to save some data in Java in various ways, to a File , to a String , to System.out ... And I ended up with 3 methods doing pretty much the same thing. So I changed them into a single method with an OutputStream as a parameter. I wrote a few things to a single OutputStream, e.g. some text, a serialized object, another serialized object, some numerical data ... But now I'm stuck. I overlooked the fact that I cannot distinguish between the different things that have been written. I

Why does my InputStream hold old values?

孤者浪人 提交于 2020-01-06 02:46:06
问题 I am sending an IR signal to the IR receiver which is passed through the BT module to the InputStream of the Android application. Every time I press a button on the emitter, I send 100 bytes which then I expect to get into the InputStream (is there a way to handle an exception when there is no 100 bytes because the packet got corrupted?). This is my code for reading InputStream and putting values into the byte[] buffer : public int read(final InputStream input, final byte[] buffer) throws