outputstream

Why Java OutputStream.write() Takes Integer but Writes Bytes

假如想象 提交于 2019-11-30 05:50:53
问题 I am writing an OutputStream, just noticed this in the OutputStream interface, public abstract void write(int b) throws IOException; This call write one byte to the stream but why it takes integer as an argument? 回答1: Actually I've been working with bytes a bit lately and they can be annoying. They up-convert to ints at the slightest provocation and there is no designation to turn a number into a byte--for instance, 8l will give you a long value 8, but for byte you have to say (byte)8 On top

Handle Input using StreamGobbler

拜拜、爱过 提交于 2019-11-30 05:11:39
问题 I have been through the StreamGobbler at the following URL JavaWorld : Stream Gobbler I understand the usage and the reason on why it has been implemented. However the scenarios covered are only those wherein there could be an output from the command / handling error's. I do not find any scenario wherein StreamGobbler is used to handle inputs. For example, in mailx , I have to specify the body of the email, which I have done in the following format Process proc = Runtime.getRuntime().exec(cmd

When does a stream close if its not closed manually?

早过忘川 提交于 2019-11-30 03:49:19
问题 I would like to know when does a stream close if its not closed manually. By this I mean, will the stream be closed if the scope of its reference is no more? Consider the following sample scenario. Class A{ InputStream in; OutputStream out; A(){ // Initialize and create the streams. } ... } Class B{ public void myMethod(){ A a = new A(); System.out.println("End of my method.") } ... } Here, once I am done with the stream, I am exiting myMethod() but the program which in turn the process, is

Is it overkill to use BufferedWriter and BufferedOutputStream together?

為{幸葍}努か 提交于 2019-11-30 03:16:25
问题 I want to write to a socket. From reading about network IO, it seems to me that the optimal way to write to it is to do something like this: OutputStream outs=null; BufferedWriter out=null; out = new BufferedWriter( new OutputStreamWriter(new BufferedOutputStream(outs),"UTF-8")); The BufferedWriter would buffer the input to the OutputStreamWriter which is recommended, because it prevents the writer from starting up the encoder for each character. The BufferedOutputStream would then buffer the

Java OutputStream Skip (offset)

浪子不回头ぞ 提交于 2019-11-30 03:09:23
问题 I am trying to write a function that takes File object, offset and byte array parameters and writes that byte array to a File object in Java. So the function would look like public void write(File file, long offset, byte[] data) But the problem is that the offset parameter is long type, so I can't use write() function of OutputStream, which takes integer as an offset. Unlike InputStream, which has skip(long), it seems OutputStream has no way to skip the first bytes of the file. Is there a

How to put the content of a ByteBuffer into an OutputStream?

走远了吗. 提交于 2019-11-29 23:39:41
I need to put the contents of a java.nio.ByteBuffer into an java.io.OutputStream . (wish I had a Channel instead but I don't) What's the best way to do this? I can't use the ByteBuffer's array() method since it can be a read-only buffer. I also may be interspersing writes to the OutputStream between using this ByteBuffer and having a regular array of byte[] which I can with use OutputStream.write() directly. ng. Look at Channels.newChannel(OutputStream) . It will give you a channel given an OutputStream. With the WritableByteChannel adapter you can provide the ByteBuffer which will write it to

Android BluetoothSocket OutputStream write blocks infinitely

半世苍凉 提交于 2019-11-29 20:15:56
问题 I need to programmatically write data of say 1 to 100 MB in chunks of 1024 bytes to the remote Bluetooth device. Both are android devices. Here is a sample code snippet in my client program to transfer data – bTSocket.connect(); //connect to remote BT device DataOutputStream outStream = new DataOutputStream(bTSocket.getOutputStream()); byte[] buffer = new byte[1024]; int bytesToTransfer = 1000000; while (bytesToTransfer > 0) { outStream.write(buffer); outStream.flush(); bytesToTransfer -=

Capturing an c# executable output from another C# program

核能气质少年 提交于 2019-11-29 15:24:31
I am executing a C# program i.e a .exe from another C# program. but the .exe has some Console.WriteLine() in its program. I want to get the standard output into my C# program. for example, Consider a C# executable i.e 1.exe and there is another Program 2.cs. I am calling from 2.cs 1.exe. Now there is some output that the console is displaying from 1. exe. But I want the ouput in my program 2.cs. for displaying information to user. Is it possible? Please help Thanks Sai sindhu You can use ProcessStartInfo.RedirectStandardOutput Property Process compiler = new Process(); compiler.StartInfo

Is there a way to make PHP progressively output as the script executes?

倖福魔咒の 提交于 2019-11-29 07:47:38
So I'm writing a disposable script for my own personal single use and I want to be able see how the process is going. Basically I'm processing a couple of thousand media releases and sending them to our new CMS. So I don't hammer the CMS, I'm making the script sleep for a couple of seconds after every 5 requests. I would like - as the script is executing - to be able to see my echo s telling me the script is going to sleep or that the last transaction with the webservice was successful. Is this possible in PHP? Thanks for your help! Iain Use ob_flush to send any data in the buffer. So you can

how to write array to outputStream in Java

混江龙づ霸主 提交于 2019-11-29 07:21:14
I want to send more than one random value though Socket . I think array is the best way to send them..But I don't know how to write an array to Socket outputStream ? My java Class import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.Socket; import java.io.*; import java.util.Random; class NodeCommunicator { public static void main(String[] args) { try { Socket nodejs = new Socket("localhost", 8181); Random randomGenerator = new Random(); for (int idx = 1; idx <= 1000; ++idx){ Thread.sleep(500); int randomInt = randomGenerator.nextInt(35)