bufferedreader

How to read a line from InputStream without buffering the input? [duplicate]

痴心易碎 提交于 2019-12-05 15:33:16
This question already has an answer here: Reading lines from an InputStream without buffering 3 answers I have an InputStream which contains a line as a string and then binary data. If I read the line using new BufferedReader(new InputStreamReader(inputStream)) , the binary data is being also read and cannot be re-read. How can I read a line without reading the binary data as well? * Update: It seems that InputStreamReader buffers (reads ahead) as well :( Posted another answer to directly read from the InputStream. Eventually did it manually :( I guess I missed a lot of cases like \r and white

Read in N Lines of an Input Stream and print in reverse order without using array or list type structure?

核能气质少年 提交于 2019-12-05 11:20:37
Using the readLine() method of BufferedReader , can you print the first N lines of a stream in reverse order without using a list or an array? I think you can do it through recursion with something like: void printReversed(int n) { String line = reader.readLine(); if (n > 0) printReversed(n-1); System.out.println(line); } How about recursion to reverse the order? Pseudo code: reverse(int linesLeft) if (linesLeft == 0) return; String line = readLine(); reverse(linesLeft - 1); System.out.println(line); Nice question. Here you have one solution based on coordinated threads. Although it's heavy on

java telnet socket : BufferedReader / BufferedWriter

喜夏-厌秋 提交于 2019-12-05 10:28:13
My server opens a telnet port on 23999 and when I give telnet localhost 23999 , it shows below : < BP-SAS ==> bplin19 !>telnet 0 23999 Trying 0.0.0.0... Connected to 0. Escape character is '^]'. Please enter password to authenticate: (here i give password for example abc123) Enter 'help' at any point to get a listing of all registered commands... BAS> log set-info 1 ( commad i have entered and it does somthing ) Now Instead of open like this, I have to write java code which does this thing. connect to host 23999 port enter password enter commad Socket soc=new Socket("192.168.9.7",23999); while

Convert `BufferedReader` to `Stream<String>` in a parallel way

寵の児 提交于 2019-12-05 07:58:47
Is there a way to receive a Stream<String> stream out of a BufferedReader reader such that each string in stream represents one line of reader with the additional condition that stream is provided directly (before reader read everything)? I want to process the data of stream parallel to getting them from reader to save time. Edit: I want to process the data parallel to reading. I don't want to process different lines parallel. They should be processed in order. Let's make an example on how I want to save time. Let's say our reader will present 100 lines to us. It takes 2 ms to read one line

buffered reader not receiving data from socket

六眼飞鱼酱① 提交于 2019-12-05 01:16:00
问题 I am writing a client application that will receive a continuous flow of data through tcp/ip. The problem I'm having is that the buffered reader object isn't receiving any data and is hanging at the readline method. The way the server works is that you connect to it, and then send authentication information in order to receive data. The gist of my code is below socket = new Socket(strHost, port); authenticate(); inStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));

CipherInputStream is Empty when trying to decrypt file

ⅰ亾dé卋堺 提交于 2019-12-04 22:06:32
I'm trying to write a few helper methods to take care of reading and writing an encrypted file. I have two methods which successfully fulfill this and return an InputStream or an OutputStream (which are really the Cipher version) that I can use to read or write to the file. I have confirmed that these methods work peachy keen when wrapped with an Object stream and used to read and write an encrypted Object to file. However, the problem arises when I try to read from an encrypted text file. I can verify that the String I feed it is being encrypted and written to the correct file, but when I try

Android - open file from phone memory using intent

不羁岁月 提交于 2019-12-04 21:25:34
I am working on an app that takes the .txt file from a phone as input and prints it on the TextView, public class MainActivity extends AppCompatActivity { Button button; Intent intent;private StringBuilder text = new StringBuilder(); private InputStream getResources(String s) { return null; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.btn); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { intent = new Intent(Intent

Use BufferedReader and InputStream together

浪子不回头ぞ 提交于 2019-12-04 20:15:53
I use a BufferedReader to read lines from an InputStream. When I read something directly from the InputStream, the BufferedReader ignores my read and continues reading at the same location. Is it possible to prevent this behavior? If not what is a good practice to do this? PS: Here's my code: byte[] ba = new byte[1024*1024]; int off = 0; int len = 0; do { len = Integer.parseInt(br.readLine()); in.read(ba, off, len); br.readLine(); off += len; } while(len > 0); in is my inputstream and br my bufferedreader. If not what is a good practice to do this? This is not a good approach to read by 2

multiprocessing.pool.MaybeEncodingError: Error sending result: Reason: 'TypeError(“cannot serialize '_io.BufferedReader' object”,)'

孤者浪人 提交于 2019-12-04 15:01:56
I get the following error: multiprocessing.pool.MaybeEncodingError: Error sending result: '<multiprocessing.pool.ExceptionWithTraceback object at 0x7f758760d6a0>'. Reason: 'TypeError("cannot serialize '_io.BufferedReader' object",)' When running this code: from operator import itemgetter from multiprocessing import Pool import wget def f(args): print(args[1]) wget.download(args[1], "tests/" + target + '/' + str(args[0]), bar=None) if __name__ == "__main__": a = Pool(2) a.map(f, list(enumerate(urls))) #urls is a list of urls. What does the error mean and how can I fix it? First couple of

Java: Outputting text file to Console

爱⌒轻易说出口 提交于 2019-12-04 14:47:07
I'm attempting to output a text file to the console with Java. I was wondering what is the most efficient way of doing so? I've researched several methods however, it's difficult to discern which is the least performance impacted solution. Outputting a text file to the console would involve reading in each line in the file, then writing it to the console. Is it better to use: Buffered Reader with a FileReader, reading in lines and doing a bunch of system.out.println calls? BufferedReader in = new BufferedReader(new FileReader("C:\\logs\\")); while (in.readLine() != null) { System.out.println