outputstream

How can I read different groups of data on the same InputStream, using different types of InputStreams for each of them?

坚强是说给别人听的谎言 提交于 2020-01-06 08:43:30
问题 I needed to save some data in Java in various ways, to a File , to a String , to System.out ... And I ended up with 3 methods doing pretty much the same thing. So I changed them into a single method with an OutputStream as a parameter. I wrote a few things to a single OutputStream, e.g. some text, a serialized object, another serialized object, some numerical data ... But now I'm stuck. I overlooked the fact that I cannot distinguish between the different things that have been written. I

Using inputStream and OutputStream to read and write data to a process

泄露秘密 提交于 2020-01-05 23:45:08
问题 I am currently running a .class file as a process. The .class file is a simple program that asks the user to input a number, takes the input and prints the user's input back to the screen. Up to now, i have managed to print the "Enter a number: " statement from the process on the console through InputStream and write the input entered by the user through OutputStream . I am unable to print the last statements on the screen, which should be "You entered : " + userinput My code is: String

Loading and saving resources inside a runnable jar? [duplicate]

你离开我真会死。 提交于 2020-01-02 21:54:10
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How can a Java program use files inside the .jar for read and write? I am in the process of creating a game, and I want it all to run from on runnable jar file, so all of my resources (images and text files) are going to be inside the jar file. The problem that I'm having with this is that it is extremely difficult to deal with files inside the jar. I am using eclipse, which can sometimes play tricks on you

PHP: close output stream

馋奶兔 提交于 2020-01-02 03:37:11
问题 Is it possible to close the output stream of a PHP script? I have a script which needs to do some post processing, but during and after the post processing it won't send any data to the client anymore, so I'd like to close the connection before the post processing. Edit: In my application I have a cache which needs to be rebuild every now and then. However, I don't want to slow a user down. What I want is to determine at the end of the script if the cache needs to be rebuild. So I want to

How to modify the generated SOAP request?

浪子不回头ぞ 提交于 2020-01-01 08:47:12
问题 I'm at the stage where I created an output interceptor and I get an OuputStream out of the SOAP message. But how could I modify the SOAP envelope right before sending it to the endpoint? I would like to delete some xml elements. 回答1: one way could be to get the document and run it through XSLT transform. You can get at the document in the handleMessage of your interceptor by calling @Override public void handleMessage(SoapMessage message) throws Fault{ SOAPMessage saaj = message.getContent

Cancelling background-worker

試著忘記壹切 提交于 2019-12-25 07:46:55
问题 I have the following problem and I hope someone will be able to help me with it. I have a worker in VB .net (2010) which runs a shell-program. The shell program is a service and output stuff like: Server initializing... Server opening port... more info... I am able to 'catch' the output of the shell and add it to a textbox (using set text function). And I am able to Cancel the worker by clicking on a stopbutton, however when there is no more output by the shell I cannot stop the worker

How to write numbers to a file and make them readable between Java and C#

时光怂恿深爱的人放手 提交于 2019-12-25 04:28:24
问题 I'm into a "compatibility" issue between two versions of the same program, the first one written in Java, the second it's a port in C#. My goal is to write some data to a file (for example, in Java), like a sequence of numbers, then to have the ability to read it in C#. Obviously, the operation should work in the reversed order. For example, I want to write 3 numbers in sequence, represented with the following schema: first number as one 'byte' (4 bit) second number as one 'integer' (32 bit)

How to load streamed data directly into a BufferedImage

跟風遠走 提交于 2019-12-25 00:18:55
问题 I am using the code provided by this accepted answer to send a list of files over a socket in Java. My goal is to be receiving a list of images. What I would like to do is read these images directly into memory as BufferedImages before writing them to disk. However, my first attempts, which was to use ImageIO.read(bis) (again, see the attached question) failed, as it attempted to continue reading beyond the end of the first image file. My current idea is to write the data from the socket to a

what is the fastest way to write a byte array to socket outputstream in java

六眼飞鱼酱① 提交于 2019-12-24 17:27:34
问题 As the title, and assume the size of byte array is no larger than 16 Kbytes. Currently I am implementing a middleware for MySQL (like MySQL Proxy), which requires high throughput. but the overhead caused by reading data from socket and writing data to socket. For now, I use in = new DataInputStream(new BufferedInputStream(socket.getInputStream())) and out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())) When read data and write, I use in.read(byte[] b) and out.write

WriteAsync with timeout

亡梦爱人 提交于 2019-12-24 16:37:31
问题 I try to code a simple async write with timeout as below and expect the function to throw a TaskCanceledException given a very large buffer and small waitTime. However, this does not happen. WriteAsync will block for many seconds until the write completes. What am I missing? public async void WriteWithTimeout(Stream os, byte[] buf, int waitMs) { CancellationTokenSource tokenSource = new CancellationTokenSource(waitMs); // cancel after waitMs milliseconds. await os.WriteAsync(buf, 0, buf