Questions tagged [bytearrayoutputstream]

A mechanism for writing byte data to a stream

A ByteArrayOutputStream is a mechanism for writing an array of byte data to a stream. A stream is usually comprised of data to write to a local file, or data being transmitted to a remote server over a network protocol such as HTTP or FTP. This type of stream would send the contents of a byte array, one byte at a time, through the stream to the destination, until the entire array has been sent.

203 questions
88
votes
5 answers

Most efficient way to create InputStream from OutputStream

This page: http://blog.ostermiller.org/convert-java-outputstream-inputstream describes how to create an InputStream from OutputStream: new ByteArrayInputStream(out.toByteArray()) Other alternatives are to use PipedStreams and new threads which is…
Vagif Verdi
  • 4,550
  • 1
  • 24
  • 31
81
votes
2 answers

Create a file from a ByteArrayOutputStream

Can someone explain how I can get a file object if I have only a ByteArrayOutputStream. How to create a file from a ByteArrayOutputStream?
Al Phaba
  • 5,847
  • 11
  • 43
  • 70
29
votes
5 answers

Convert Contents Of A ByteArrayInputStream To String

I read this post but I am not following. I have seen this but have not seen a proper example of converting a ByteArrayInputStream to String using a ByteArrayOutputStream. To retrieve the contents of a ByteArrayInputStream as a String, is using a…
Mushy
  • 2,225
  • 9
  • 30
  • 50
29
votes
3 answers

How to convert Byte array to ByteArrayOutputStream

I need to convert a byte array to ByteArrayOutputStream so that I can display it on screen.
Arun
  • 2,793
  • 4
  • 29
  • 40
21
votes
3 answers

BufferedOutputStream vs ByteArrayOutputStream

Is there any advantage in wrapping a BufferedOutputStream around a ByteArrayOutputStream instead of just using the ByteArrrayOutputStream by itself?
Hank
  • 3,157
  • 7
  • 43
  • 82
18
votes
3 answers

Convert OutputStream to ByteArrayOutputStream

I am trying to convert an OutputStream to a ByteArrayOutput Stream. I was unable to find any clear simple answers on how to do this. This question was asked in the title of the question on StackOverflow, but the body of the question aske how to…
Bill Smith
  • 187
  • 1
  • 1
  • 8
17
votes
9 answers

Java: Memory efficient ByteArrayOutputStream

I've got a 40MB file in the disk and I need to "map" it into memory using a byte array. At first, I thought writing the file to a ByteArrayOutputStream would be the best way, but I find it takes about 160MB of heap space at some moment during the…
user683887
  • 1,180
  • 1
  • 9
  • 20
15
votes
2 answers

How to create a multipart zip file and read it back?

How would I properly zip bytes to a ByteArrayOutputStream and then read that using a ByteArrayInputStream? I have the following method: private byte[] getZippedBytes(final String fileName, final byte[] input) throws Exception { …
Benny
  • 1,378
  • 2
  • 15
  • 34
12
votes
6 answers

How to use ByteArrayOutputStream and DataOutputStream simultaneously in Java?

I'm having quite a problem here, and I think it is because I don't understand very much how I should use the API provided by Java. I need to write an int and a byte[] into a byte[]. I thought of using a DataOutputStream to solve the data writing…
Manuel Araoz
  • 14,795
  • 21
  • 67
  • 91
12
votes
3 answers

Closing ByteArrayOutputStream in an Android application

In an Android application I'm sending a picture taken from the Camera Intent so I need to transform a Bitmap to a byte array. To do this I use a ByteArrayOutputStream as follow: private byte[] getRawImageData(Bitmap source) { …
bvidal
  • 2,592
  • 1
  • 25
  • 33
11
votes
6 answers

Java: IOException when writing to a ByteArrayOutputStream?

Since ByteArrayOutputStream simply writes to memory, an IOException should never occur. However, because of the contract of the OutputStream interface, all stream operations define IOException in their throws clause. What is the correct way to…
Tony the Pony
  • 37,471
  • 63
  • 170
  • 273
8
votes
3 answers

Null Pointer Exception when trying to compress Bitmap

I'm getting a null pointer exception when trying to compress a bitmap so I can send it to a ByteArrayOutputStream to get a byte array. I need this byte array so I can upload the image to my Parse database as a ParseFile. The log error is shown…
8
votes
3 answers

How to play a video from Amazon S3 in Android App?

I use aws-android-sdk-1.4.3/samples/S3_SimpleDB_SNS_SQS_Demo to preview my files stored on Amazon (Amazon Simple Storage Service). Looking through code I saw that they use this, to acces the files: com.amazonaws.demo.s3.S3.getDataForObject (line…
7
votes
1 answer

Read parquet data from ByteArrayOutputStream instead of file

I would like to convert this code: import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.parquet.column.page.PageReadStore; import org.apache.parquet.example.data.simple.SimpleGroup; import…
chrismead
  • 1,833
  • 2
  • 17
  • 26
7
votes
1 answer

Why you can read data from already closed ByteArrayOutputStream?

I'm wondering why you still can read bytes from already closed ByteArrayOutputStream. Doesn't this line from docs mean the opposite? public void close (): Closes this stream. This releases system resources used for this stream. Sample code:…
Roman
  • 906
  • 1
  • 10
  • 23
1
2 3
13 14