Questions tagged [datainputstream]

A DataInputStream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.

The DataInputStream class enables you to read Java primitives from InputStream's instead of only bytes. Wrap an InputStream in a DataInputStream and then you can read primitives from it. DataInputStreams represent Unicode strings in a format that is a slight modification of UTF-8.

339 questions
2
votes
2 answers

how to send a command at runtime using "su" and get all lines back from DataInputStream

I am working on a program that needs to be able to determine what is on the android device at Xlocation. I am using "su ls Xlocation" I want to get back and array list of files but only manage to get back the first Item. Am I missing a command that…
SatanEnglish
  • 1,346
  • 1
  • 13
  • 22
2
votes
3 answers

Java: InputStreams and OutputStreams being shared

Can I share an InputStream or OutputStream? For example, let's say I first have: DataInputStream incoming = new DataInputStream(socket.getInputStream())); ...incoming being an object variable. Later on I temporarily do: BufferedReader dataReader =…
fast-reflexes
  • 4,891
  • 4
  • 31
  • 44
2
votes
3 answers

Java primitive data type byte and class Byte

Background: I have an assignment where I'm going to pass information through sockets to a very limited extent. It can be a maximum of 10 bytes per message and I was thinking I'm gonna send just one byte (since one byte is enough to signal 256…
fast-reflexes
  • 4,891
  • 4
  • 31
  • 44
2
votes
1 answer

Android Java - DataInputStream to String from Socket

I am having a bit of trouble writing an android app that can communicate with my server to send and receive data. So the jist of it is that my server is written in Qt C++ and, of course, my app is written in java for android. A lot of complications…
2
votes
2 answers

Read an int[] from a DataInputStream

I'm looking for a way to read a large number of ints from a DataInputStream and load them into an array. I know exactly how many ints I need to read, but it'd be nice if there was a cleaner way than to simply iterate. There is already a way to do…
Alexis King
  • 43,109
  • 15
  • 131
  • 205
2
votes
3 answers

Transmiting/receiving compressed data with sockets: how to properly receive the data sent from the client

I have developed a client-server chat using the Sockets and it works great, but when I try to transmit data with Deflate compression it doesn't work: the output is "empty" (actually it's not empty, but I'll explain below). The…
HBv6
  • 3,487
  • 4
  • 30
  • 43
1
vote
4 answers

Java BufferedInputStream.read() IndexOutOfBounds

i'm want to code a method that reads part from files into byte-arrays. for this i'm using fileinputstream and a buffered inputstream. like this: fis = new FileInputStream(file); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); I…
Tony B
  • 344
  • 5
  • 19
1
vote
2 answers

How to read parts of binary file again if DataInputStream does not support mark/reset

I need to read a section of a structured binary file by passing an index. However, DataInputStream does not support mark/reset. How can I achieve what I want? Are there any other classes that allow me to easily achieve this? import…
user1040876
  • 31
  • 1
  • 3
  • 6
1
vote
2 answers

strip data from text file using regex

Im going to start by posting what the data from the text file looks like, this is just 4 lines of it, the actually file is a couple hundred lines long. Friday, September 9 2011 5:00AM - 11:59PM STH 1102 HOLD DO NOT BOOK …
Beef
  • 1,413
  • 6
  • 21
  • 36
1
vote
1 answer

strip data from a text file

Im going to start by posting what the date in the text file looks like, this is just 4 lines of it, the actually file is a couple hundred lines long. Friday, September 9 2011 -STV 101--------05:00 - 23:59 SSB 4185 Report Printed on…
Beef
  • 1,413
  • 6
  • 21
  • 36
1
vote
0 answers

DataInputStream not getting the right value

I'm trying to setup a server-client file transfer where one user sends a file to the server, and the server sends that file to another user (users in this case are instances of the Client.java class). From the first client to the server, everything…
1
vote
2 answers

Java DataInputStream.read() causing 20% constant CPU usage while being blocked.

I have a server-side application opens a socket thread for each connected client. I have a DataInputStream in each thread, which calls read(byte[]array) to read data. I also set the socket timeout to a few minutes. The main code is something like…
Lee
  • 103
  • 1
  • 11
1
vote
2 answers

java.io.UTFDataFormatException while reading file entry name

Im trying to "pack" several files (previously inside a jar archive) in another single non-jar file by using DataInputStream / DataOutputStream. The idea was: First int = number of entries First UTF is the first entry name …
1
vote
1 answer

How can I read a String with System.in using a InputStream or DataInputStream

I am trying to read a String with System.in using an InputStream o DataInputStream, maybe I can use BufferedInputStream, but I don't know how to use it, I was searching for bu I don't understand how does it works, I am trying to dos something like…
1
vote
1 answer

EOF Exception for ObjectInputStream test

I am trying to test readObject method for reading object from ObjectInputStream @Test public void testReadObject() throws Exception { ObjectInputStream in = new ObjectInputStream(System.in); ... } I am getting java.io.EOFException for…
Ayman Arif
  • 1,456
  • 3
  • 16
  • 40