Questions tagged [bytearrayinputstream]

ByteArrayInputStream is a Java and Android class implementing a stream that reads data from a byte array.

107 questions
38
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,535
  • 10
  • 33
  • 54
33
votes
5 answers

How to create ByteArrayInputStream from a file in Java?

I have a file that can be any thing like ZIP, RAR, txt, CSV, doc etc. I would like to create a ByteArrayInputStream from it. I'm using it to upload a file to FTP through FTPClient from Apache Commons Net. Does anybody know how to do it? For…
itro
  • 7,006
  • 27
  • 78
  • 121
18
votes
4 answers

How do I take a ByteArrayInputStream and have its contents saved as a file on the filesystem

I have an image which is in the form of a ByteArrayInputStream. I want to take this and make it something that I can save to a location in my filesystem. I've been going around in circles, could you please help me out.
Ankur
  • 50,282
  • 110
  • 242
  • 312
16
votes
3 answers

Why to use ByteArrayInputStream rather than byte[] in Java

As I understand ByteArrayInputStream is used to read byte[] data. Why should I use it rather than simple byte[] (for example reading it from DB). What is the different between them?
Sahar Menashe
  • 1,945
  • 2
  • 18
  • 17
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,508
  • 3
  • 18
  • 34
10
votes
4 answers

What's the difference between InputStream and ByteArrayInputStream?

The following code is extracted from the java web start chapter of the core java volume 1. ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream printOut = new PrintStream(out); printOut.print(panel.getText()); …
scobur
  • 275
  • 2
  • 3
  • 9
10
votes
2 answers

Receive byte[] using ByteArrayInputStream from a socket

Here is the code but got error: bin = new ByteArrayInputStream(socket.getInputStream()); Is it possible to receive byte[] using ByteArrayInputStream from a socket?
hkguile
  • 4,235
  • 17
  • 68
  • 139
8
votes
1 answer

LibGDX creating texture from base64 PNG ByteArrayInputStream

I just decided to make the change from Slick2D to LibGDX. However, for me to be able to port my game over to LibGDX I need help understanding how to create textures in LibGDX from my game data files. My game data files are encrypted and the images…
7
votes
3 answers

Byte array to buffered image conversion slow

I have a simple server-side code that receives a byte array representing an image in JPEG format and returns the dimensions of the image. public String processImage(byte[] data) { long startTime = System.currentTimeMillis(); …
baekacaek
  • 1,527
  • 3
  • 22
  • 45
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…
6
votes
1 answer

How can i convert ByteArrayInputStream to jpeg and display on android mobile?

1.i get the android camera data convert to bitmao if (mBitmap == null) //create Bitmap image first time { Camera.Parameters params = camera.getParameters(); width_ima = params.getPreviewSize().width; …
badboy_tqj
  • 300
  • 2
  • 14
4
votes
2 answers

Should streams be closed after every use?

I am currently working on a UDP server for a game. In this server use a ByteArrayInputStream and a ObjectInputStream every tick to convert serialized bytes to objects. Is it more efficient to create one variable for the streams and close them once…
4
votes
1 answer

Is there a better way to grab a list of Avro records from an InputStream?

I have a ByteArrayInputStream that was serialized with a List which is an implementation of SpecificRecord. I could not find a way for Avro to know about the list that was serialized so I did a hackish way to loop through the…
4
votes
5 answers

Java BufferedReader.readLine() not waiting for EOL?

Sorry if I'm missing something obvious here...but please take a look at this code snippet: String readString; String writeString = "O hai world."; BufferedReader br = new BufferedReader( new InputStreamReader( new…
3
votes
3 answers

Read the binary image data from a URL into a ByteArrayInputStream from HttpUrlConnect::URL

I'm trying to pull the image from a URL and read it directly into a ByteArrayInputStream. I found one way of doing it, but it requires an image type, and there will be various image types, so I'd like to find a simple way to just read the binary…
BenW
  • 737
  • 10
  • 41
1
2 3 4 5 6 7 8