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.

234 questions
6
votes
2 answers

Create an in-memory FileDescriptor

FileDescriptor API in Android says: Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. I want to create a…
5
votes
3 answers

Exceeding byte[] array length (over int upper limit) - java.lang.ArrayIndexOutOfBoundsException

I have a ByteArrayOutputStream object that I'm getting the following error for: java.lang.ArrayIndexOutOfBoundsException at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:113) I am trying to load a file that is several gigs into it…
Brian
  • 73
  • 1
  • 3
  • 7
5
votes
4 answers

Concatenate ByteArrayOutputStream

public byte[] toByteArray() { try { ByteArrayOutputStream objectStream = dataObject.toByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(objectStream); dout.writeUTF(recordid); …
Vincent
  • 6,058
  • 15
  • 52
  • 94
5
votes
1 answer

Compressing(zip) List of files with ZipOutPutStream Java

I`m trying to compress a list of Xml converted on Strings, save them in only one zip file and returning as a body of a POST on restful. But everytime I save the file I get the error "The archive is either in unknown format or damaged". protected…
5
votes
1 answer

Why ByteArrayOutputStream.close() throws IOException?

Why ByteArrayOutputStream.close is declared with throws IOException? First, de facto it can't throw anything, because its body is empty. Second, de jure it can't throw anything, because its documentation says "closing a ByteArrayOutputStream has no…
Sasha
  • 3,599
  • 1
  • 31
  • 52
5
votes
1 answer

A resource was acquired at attached stack trace but never released - Error

I'm not sure why I am getting this error, 2 out of 5 times I set the wallpaper using the emulator, I get the error - "A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource…
Jack
  • 2,043
  • 7
  • 40
  • 69
5
votes
2 answers

what is the best way to close a ByteArrayOutputStream?

I need to optimize a application that uses too much heap memory. I'm having problem in close a ByteArrayOutputStream variable after using the same. I've tried to do using close() but it does not work. this is the code: ByteArrayOutputStream…
4
votes
1 answer

java wrap GZIPOutputStream & ByteArrayOutputStream together - what am I doing wrong?

Main.java import java.io.IOException; public class Main { private final CompressedOutputStream m_cos; public static void main(String[] args) { try { final Main m = new Main(new…
Poni
  • 11,061
  • 25
  • 80
  • 121
4
votes
1 answer

How to set array of records Using GenericRecordBuilder

I'm trying to turn a Scala object (i.e case class) into byte array. In order to do so, I'm inserting the object content into a GenericRecordBuilder using its specific schema, and eventually using GenericDatumWriter i turn it into a byte array. I…
Nir
  • 601
  • 7
  • 21
4
votes
2 answers

Writing contents of ByteArrayOutputStream to a file using NIO FileChannel

I have a method that generates a ByteArrayOutputStream and I want to put those contents in a file using FileChannel. With FileOutputStream, I could do this: ByteArrayOutputStream baos = MyClass.myMethod(); // get my stream FileOutputStream out = new…
quantumSoup
  • 27,197
  • 9
  • 43
  • 57
4
votes
2 answers

Strict Mode complains on resource leak

Strict mode complains the following: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.: **response = httpclient.execute(httpPost);** Below is my code: …
muneikh
  • 2,067
  • 5
  • 25
  • 59
4
votes
5 answers

Java writing to ByteArrayOutputStream memory leak

I am writing bytes of image to ByteArrayOutputStream then sending it over socket. The problem is, when I do ImageIO.write(image, "gif", byteArray); Memory goes up VERY much, kinda memory leak. I send using this ImageIO.write(image, "gif",…
4
votes
1 answer

Android - How to convert picture from webview.capturePicture() to byte[] and back to bitmap

I'm trying to capture the picture I'm getting from webview.capturePicture() to save it to an sqliteDatabase, to do I need to convert the image to a byte[] to be able to save it as a BLOB in my table, and then by able to retrieve that byte[] and…
codeskraps
  • 1,461
  • 2
  • 12
  • 13
3
votes
3 answers

Why did Java 11 add writeBytes​(byte[] b) method to the ByteArrayOutputStream class while the write​(byte[] b) method did the same?

Oracle added writeBytes​(byte[] b) method to the ByteArrayOutputStream class since Java 11. This method takes a byte array and writes it to ByteArrayOutputStream. However, ByteArrayOutputStream extends OutputStream class that defines a write​(byte[]…
MTB
  • 405
  • 1
  • 5
  • 12
3
votes
1 answer

java byte array output stream gives nothing

I have the following code and I can't figure out why it won't work: final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final String p1 = "HELLO WORLD"; process(p1, bos); Assert.assertEquals("BOS value should be: "+p1, p1,…
Mohamed Nuur
  • 5,536
  • 6
  • 39
  • 55
1
2
3
15 16