outputstream « API « Java I/O Q&A





1. Get an OutputStream into a String    stackoverflow.com

What's the best way to pipe the output from an java.io.OutputStream to a String in Java? Say I have the method:

  writeToStream(Object o, OutputStream out)
Which writes certain data from the object ...

2. Is there a Null outputstream in Java?    stackoverflow.com

I need to specify an OutputStream for an API I'm using, but I don't actually have a need for the output. Does Java have an OutputStream equivalent to > /dev/null ...

3. How can I implement an OutputStream that I can rewind?    stackoverflow.com

After writing out some processed content to an output stream, I need to revisit the beginning of the stream and write out some content metadata. The data I'm writing is ...

4. Switching Writers on an OutputStream in Java    stackoverflow.com

I have one method that opens a file and passes off to another function to write some data to it. That second method wants to use PrintWriter to write its data. ...

5. interface hunt for something like Appendable or OutputStream    stackoverflow.com

Hmmm. I'm trying to write a class that accepts bytes, and would like to implement a well-known interface for this purpose. java.io.OutputStream is an abstract class, not an interface (why???) ...

6. Java - passing input into external C/C++ application    stackoverflow.com

I'm trying to enter some value in external application using Java. Java application looks like this:

Runtime runtime = Runtime.getRuntime();
// ... str build ...
proc = runtime.exec(str);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
bw.write(value);
bw.flush();
bw.close();
if (proc.waitFor() ...

7. How to achieve highest performance possible with any kind of OutputStream in java?    stackoverflow.com

I need to write blocks of data (characters) and I don't care about the sequence of those blocks. I wonder what kind of OutputStream I should use to achieve high ...

8. Multiple read from an InputStream at different rates    stackoverflow.com

I'm about to load an online content (say an audio file). If I just open a connection to the remote file (for example by use of new URL().openStream()) and pass the ...

9. Connecting an input stream to an outputstream    stackoverflow.com

I saw some similar, but not-quite-what-i-need threads. I have a server, which will basically take input from a client, client A, and forward it, byte for byte, to another client, client B. I'd ...





10. cancel a read from an InputStream    stackoverflow.com

Currently I am using an ObjecInputStream to read from a Socket, and everything works fine using this simple code:

ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
Object response = input.readObject();
Now I want to somehow cancel ...

11. java outputstream java.lang.OutOfMemoryError: Java heap space    stackoverflow.com

I am trying to publish a large video/image file from the local file system to an http path, but I run into an out of memory error after some time... here is ...

12. Two OutputStream's instead of one?    stackoverflow.com

I am dealing with a commerical Java API that exposes only the following logging configuration:

cplex.setOut(OutputStream arg0);
I would like to have logging to two streams: a file and the console. Is it possible? ...

13. How to properly extend Java FilterOutputStream class?    stackoverflow.com

I would like to roughly monitor the progress of a file upload. I know that I can override the MultipartEntity and make the writeTo(OutputStream out) method write to a FilterOutputStream class ...

14. Adding a UTF-8 BOM to an outputStream causes the last character to not be printed in java    stackoverflow.com

I have this piece of code that adds a BOM UTF-8 to an outputstream . I need to add the BOM since Excel does not identify the UTF-8 encoding implicitly and ...

15. Create Java-Zip-Archive from existing OutputStream    stackoverflow.com

Is it possible to create a Zip-Archive in Java if I do not want to write the resulting archive to disk but send it somewhere else? The idea is that it might ...

16. Sending Large files as stream to process.getOutputStream    stackoverflow.com

I am using gzip utilities in windows machine. I compressed a file and stored in the DB as blob. When I want to decompress this file using gzip utility I am ...





17. Is there something like a rolling OutputStream?    stackoverflow.com

Is there a simple Java OutputStream that mimics a functionality similar to the log4j RollingFileAppender ? Basically it would write to a file that grows to a maximum size, then renames ...

18. Java: OutputStream and InputStream    stackoverflow.com

I have a class CBZip2OutputStream from "apache bzi2 library" , it can transform binary data stream to bzi2 data stream. But I need to archive a string. Therefore, i think, i should create ...

19. Multiple 'if' statements into one outputStream    stackoverflow.com

import java.io.*;
import java.io.File;
import java.io.FilenameFilter;

public class YDSearch{
    public void listFiles(String dir) throws IOException{

    File directory = new File(dir);
    if (!directory.isDirectory()) {
   ...

20. Proxy input/output stream issues in Java    stackoverflow.com

I've been trying for a while a few different methods to get my custom proxy to work, and the only way I've been able to so far is through use of ...

21. BufferReader in Java    stackoverflow.com

I have a problem with BufferReader and OutputStream in Java. My aim: when you insert something from a keyboard - it goes to the file. How should I correct my code?

import ...

22. FOSS LIB not HOW TODO: OutputStream that auto rolls when file gets too big or hour/day et change    stackoverflow.com

Id like an OutputStream that performs many of the functions found in the RollingXXXAppender classes in log4j. Are there any FOSS libraries that support this sort of smarts for a simple OutputStream. ...

23. InputStream from file, OutputStream to a file    stackoverflow.com

I have this code in the main class:

IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(),
    System.in, System.out);
This works very well, since System.in gets the inputs from the user nad System.out prints all the outputs. ...

24. set OutputStream for a process    stackoverflow.com

Here is a snipped code of my problem:

Process process = Runtime.getRuntime().exec(command);
    if (process.waitFor() != 0)
        throw new Exception("error");
    ...

25. Proper way to close an OutputStream in Java?    stackoverflow.com

This almost seems silly but what is the most reliable pattern to follow when closing an OutputStream? Right now I have something like the following which just seem to be try-catch-finally-overkill:

private ...

26. Building a simple chat client    stackoverflow.com

Im building a simple chat client which is only supposed to be able to send and receive messages. Im using a server running on my own computer that sends back whatever ...

27. What's the difference between Printwriter and OutputStream    stackoverflow.com

First,we have PrintWriter

java.io.File f=new java.io.File("s.txt");

   java.io.PrintWriter out=new java.io.PrintWriter(f);

   out.print(5);

   out.print(7);

   out.close();
Then we have outputstream
 java.io.File f=new java.io.File("s.txt");

 java.io.FileOutputStream out=new java.io.FileOutputStream(f);

 ...

28. Multiple files over at OutputStream    stackoverflow.com

i have this assignment in my class where i have to do a Master/slave architecture, where master is a server that provides two files (password.txt and dictonary.txt), these files he sends ...

29. OutputStream    coderanch.com

Here is a function int send (OuputStream out); How do I send this OutputStream 'out' to a URL. I can get an OuputStream to the URL by doing connection.getOutputStream(); Iam unable to comprehend as to how the URL's OutputStream relates to the one in the function parameter. In other words, Do I need to somehow read the OutputStream being passed in, ...

30. Outputstream, IllegalStateException    coderanch.com

Hello, I am downloading a file from the server and saving it to the client disk. He makes it but gives the following error: "2001-12-13 08:44:27 - Ctx( /PS2 ): IllegalStateException in: R( /PS2 + /save.jsp + null) OutputStream is already being used for this request" I don't know what's the problem since i close it. Here is the code "FileInputStream ...

31. OutputStream -> InputStream    coderanch.com

Thanks for the reply. It appears that the PipedOutputStream is what I need to use. However, let me be a little more specific about what I am tring to accomplish. I want to pass the output stream of the Sun Jpeg encoder to a method which accepts a JPEG InputStream. Unfortunately, I can't seem to get this to work. Here's what ...

32. InputStream -> OutputStream    coderanch.com

Here is what I need to do. Inside a servlet I have an InputStream that is the result of calling getInputStream on a Process. This is stdout from a C program that I call. I also have an OutputStream. This comes from Response.getOutputStream. What I need to do is pipe the stream from the InputStream through the OutputStream. Any ideas?

35. OutputStream to InputStream?    coderanch.com

Say you want to perform some sort of operation on the data in an InputStream, e.g. the audio data in a WAV file. You cycle through it char by char until you reach the end of the stream, writing to an OutputStream as you go. Now you want to perform a second operation on the modified stream you've just created. Is ...

36. outputstream over the net    coderanch.com

So I got some code, and it is stinking up the server it inhabits. The foul odor is ridiculous: (some preemptive notes: fname is a TextField screen is a class I made and screen.getMap() returns Color [][] ) try { URL file = new URL("ftp://neverland.ncssm.edu/~kirbyc/game/sprites/" + fname.getText()) ; URLConnection connect = file.openConnection() ; connect.setDoOutput(true) ; OutputStream out = connect.getOutputStream() ; Color ...

37. reading the content in outputstream    coderanch.com

38. outputStream doubt    coderanch.com

i know this lies inside a JUnit test, but my problem is with i/o i guess i'm quite close, because junit says: public void getNumberFromUser() throws IOException{ BufferedReader reader = new BufferedReader(new FileReader("a.txt")); ok = true; while(ok) { try { in = Integer.parseInt(reader.readLine()); ok = false; // counter++; // compare(in); } catch(NumberFormatException nfe) { System.out.println("ERROR"); } } } my JUnit test: ...

39. OutputStream: Can you spot the Problem?    coderanch.com

Hi all, What is the problem in this code? It doesn't print the string "Send Mesage" (located) in main(), although it successfully opens the SerialPort and gets the OutputStream. Even if I put lines A and B (in bold) in a while(true) loop, the application still terminates (and not still print the "Send Message"), even though I would have thought it ...

40. OutputStream truncates locked file    coderanch.com

41. Find the size of an OutputStream    coderanch.com

I suppose that depends on what you mean by "size". I'm guessing that most likely you want the total number of bytes which have been writtenthrough the stream. If that's the case, I have a simple class for that: import java.io.FilterOutputStream; import java.io.OutputStream; import java.io.IOException; public class CountingOutputStream extends FilterOutputStream { private long count; public CountingOutputStream(OutputStream out) { super(out); } public ...

42. Additional byte when reading from OutputStream    coderanch.com

All, I'm writing an application which communicates with some electronic device by serial port. I'm using javax.comm library (class SerialPort). I wrote some test cases to test if communication works. Device just sends 128 bytes starting from 0 to 128. The problem appears that when device sends byte 0x0A application receives two bytes 0x0D and 0x0A. It looks like Windows end-of-line. ...

43. Calculing the Checksum and adding it to the outputstream    coderanch.com

Hi all, I'm having problems for calculating the checksum of a message that aI have to send to a serial port. I don't understand the manual and I don't know how to do it. I have a method that send the message to the Outputstream including the STX and ETX but I don't know how to include the checksum. Here is ...

44. OutputStream already obtained    coderanch.com

Can anyone tell me why do I get the Servlet exception - "OutputStream already obtained" for the below code? <%@ page import="com.aig.cruis.actionform.GenericExcelActionForm"%> <%@ page import="com.aig.cafe.framework.util.IDataCapsule,com.aig.cruis.utils.AppValueFactory"%> <%@ page import="com.aig.cafe.framework.util.FWConstants,com.aig.cruis.common.UserBean, java.io.*"%> <% IDataCapsule dc = (IDataCapsule)request.getAttribute("RequestDataCapsule"); GenericExcelActionForm form = (GenericExcelActionForm)dc.getObject(FWConstants.ACTION_FORM); String fileName = form.getFileName(); File f = new File(fileName); if (f.exists()) { response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Type", "application/vnd.ms-excel"); response.setHeader("Content-Disposition","attachment; ...

45. Extend OutputStream    coderanch.com

I think in this case it's better to override the other write methods as well. These are mostly linked to each other, with one calling the other; usually, write(int[]) calls write(int[], int, int) and that one calls write(int). In your case it would best to focus on write(int[], int, int): public void write(int b) { int[] bytes = {b}; write(bytes); } ...

46. OutputStream.writeUTF( String s )    coderanch.com

I'm trying to implement a serverSocket wich sends a message to a client, just for testing this method ( writeUTF() ). I'm having no results, i've already read the specification but it seems to be so simple in the text, but when I implement it, i just got out of action. As follows, for server: public static void main ( String[] ...

47. OutputStream    coderanch.com

48. Differece between PrintWriter and OutputStream    coderanch.com

If I want to write some arbitrary binary data, can I use PrintWriter instead of OutputStream? I see the PrintWriter does have the write() method although it doesn't have one taking byte/byte[] arguments. If I want to write some binary data, can I just write it using write(int c)? In short what are the difference between PrintWriter and OutputSteam?

49. OutputStream contents    coderanch.com

50. OutputStream    coderanch.com

51. can an outputstream be serialised?    coderanch.com

52. OutputStream implementation    coderanch.com

There are five active threads in this applet. ThreadOne is writing data to the os stream. ThreadTwo lives in a wait/notify loop and wakes up (timeout on wait/notify) every second to update a progress bar and statistics, using values stored in a object (to which this thread has exclusive access). The other threads are living in there own wait/notify loops and ...

53. PrintWriter(OutputStream) cutoffs    coderanch.com

Hey guys - Pretty basic question. I'm using a PrintWriter attached to an OutputStream, with a readLine loop that looks like this: while ((message = BufferedReader.readLine()) != null) { PrintWriter.print(message); } The BufferedReader and PrintWriter are both attached to to Socket streams. Output loop server-side looks like this: writer.write(cmd); writer.flush(); The problem is that the strings are always cut off at ...

54. Problem with Process and his OutputStream    coderanch.com

Hey guys, i hope you can help me with my little problem. I want to execute a cmd command with the ProcessBuilder, but for some reason writing information to the stdin of the console doesnt work properly. I tried the following: public void herunterFahren(String adminaccount, String adminpass) throws RemoteException { ProcessBuilder builder = new ProcessBuilder("cmd", "/c", "runas /user:" + adminaccount + ...

55. Outputstream the file through http response    coderanch.com

I have the requirement like this 1) I have to create a file which would contain data from DB 2) and outputstream this file to http response. eg: if the request is "http://localhost/abcd/product.csv " then the user should save the file from his browser. I have never worked on IO object and I have little knowledge about FileWriter, OutputStreams. Not sure ...

56. OutputStream    coderanch.com

57. OutputStream gets a IndexOutOfBoundsException    coderanch.com

Hi, I try to copy an xsd file from a mvn project structure (the resource is in /template folder), so that , when I launch jar, the Main calls the xsd and copies it to current directory (outside the jar): public static void copyXSD() throws IOException { String XSD = "template/benerator-0.5.9.xsd"; File LOCALXSD = new File("benerator-0.5.9.xsd"); // create local file FileUtils.touch(LOCALXSD); ...

58. Outputstream string    coderanch.com

59. I/o Error when getting outputstream    coderanch.com

Hi, I get an IOException when I run my program. I am first opening a socket connection and then trying to do a sock.getOutputStream . The exception occurs at this point. It is twice that the executes this piece of code which creates a connection and calls the getOutputStream. The first time it executes fine, the second time i get an ...

60. problem using InputStream converted from OutputStream    coderanch.com

I am trying to convert an outputstream to an inputstream in order to construct a StreamSource and came across this article. http://ostermiller.org/convert_java_outputstream_inputstream.html My memory requirements eliminate using the byte array or temp file methods mentioned. I need to create the StreamSource and pass it to another method, so I can't read from the inputstream while the outputstream is being written to. ...

62. Can I connect InputStream to OutputStream    java-forums.org

I have two threads running (or plan to have) and want to know if I can connect a virtual pipe between them using InputStream and OutputStream? Is there some stream-like object that I can write to from one thread and then read from the same object from another thread? If not, what is the recommended way of doing this? The data ...

64. Handling the Process OutputStream    forums.oracle.com

now i want to do the same, and can not get it done. i want to launch a java application with a Process instance. then i want to write the output of that process to a file. I have to make the data from the outputstream writing to a file... but how???

65. OutputStream    forums.oracle.com

Hi I'm trying to write a simple client in J2ME, which will send a string to a server (running QuickServer). The server will then send a string to the client stating that it got the message. For this I use: SocketConnection sc = (SocketConnection) Connector.open("socket://localhost:1111"); OutputStream os = sc.openOutputStream(); os.write("test".getBytes()); os.flush() Problem is, the message never reaches the server. But, if ...

66. Java OutputStream help    forums.oracle.com

In addition to the javadocs, I suggest you read, "Beginning Java 2" SDK 1.4 by Ivor Horton--Wrox Press. Wait until you get to the part about Channels, FileChannels, Buffers, ByteBuffers, File Positions, etc., etc. Which covers a lot of ground in the java.io, java.nio and java.nio.channels packages. That my friend, will drive you crazy.

67. OutputStream to file    forums.oracle.com

68. InputStream and OutputStream - Already opened for input    forums.oracle.com

You can only output to a URL with some methods (POST, probably the less-commonly-used PUT, maybe others), but not on GET, which is the default. Try setting the method to POST and see if that fixes it. If not let us know. You'll probably have to cast the URLConnection to an HttpURLConnection. [add] And of course the thing on the other ...

69. FileInput and OutputStream problem    forums.oracle.com

Do not use DataInputStream or DataOutputStream when working with text files. It's a common mistake, but those are specialized classes meant to be used with a particular kind of binary file. It's entirely possible that you will never run into a situation where you need to use those classes. In order to read/write text files in an encoding that you specify, ...

71. com.ibm.wsspi.webcontainer.ClosedConnectionException: OutputStream encounte    forums.oracle.com

Hi Im getting the following exception into my WAS log, when I try to download the text file com.ibm.wsspi.webcontainer.ClosedConnectionException: OutputStream encountered error during write [6/9/10 9:21:18:749 BST] 000000df SystemErr R at com.ibm.ws.webcontainer.channel.WCCByteBufferOutputStream.write(WCCByteBufferOutputStream.java:118) [6/9/10 9:21:18:749 BST] 000000df SystemErr R at com.ibm.ws.webcontainer.srt.SRTOutputStream.write(SRTOutputStream.java:96) [6/9/10 9:21:18:749 BST] 000000df SystemErr R at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.writeOut(BufferedServletOutputStream.java:467) [6/9/10 9:21:18:749 BST] 000000df SystemErr R at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.flushBytes(BufferedServletOutputStream.java:351) [6/9/10 9:21:18:749 BST] 000000df SystemErr ...

72. OutputStream already obtained    forums.oracle.com

// the first buffer need to be validated for error, // before writing to file if(fos == null) { new requests().validate_content(new String(buffer, 0, nReadBytes)); fos = pResponse.getOutputStream(); pResponse.setContentType("application/pdf"); pResponse.setHeader("Content-Disposition", "attachment; filename=\"Estado_de_Cuenta.pdf\""); } // write the read buffer to the file fos.write(buffer, 0, nReadBytes); } if( fos != null ){ fos.flush(); fos.close(); } if( istream != null ) istream.close(); }

73. parsing/tokenizing information from OutputStream    forums.oracle.com

Well you would need to look at the [Object Serialization Stream Protocol|http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/protocol.html#8101], wouldn't you? But I would strongly advise you not to even attempt this task. It is too complex. If you need to pick apart a protocol you shouldn't be using it in the first place. Use a protocol you can already analyze.

74. Closing the outputStream    forums.oracle.com

75. OutPutStream to open a file ?    forums.oracle.com

76. java.lang.IllegalStateException: OutputStream already retrieved    forums.oracle.com

Hi , I have string object which contains string in format like below STRUSERNAME \t STRLOGINID \t NISACTIVE \n PANNER SELVAM A/L \t ARUMUGAM \t 1 \n NOR AINI BINTI DARUS \t fa00015 \t 1 \n I want to show this data in Excel ..... And I dont want to do this "write any excel file on my application server and ...

77. Create OutputStream    forums.oracle.com

78. Read contents of file into outputstream    forums.oracle.com

Thanks for the answer. But I would like to ask the following question: I have a VB application which generates a file. I have a Java application which read the contents of the file. is it possible that VB side calls the read() (file) and send() (through socket to destination) methods in Java application once the file is generated? Actually my ...

80. Append To File Using OutputStream?    forums.oracle.com

Hey, I am using OutputStream to connect to an FTP server. I am now using the ".write" command and am able to write to a file I specify. The problem is that when I write, it automatically overwrites the whole entire file. How can I make it so it just appends the new information instead of overwriting the whole file? If ...

81. InputStream to OutputStream    forums.oracle.com

what do you mean by "but it you look at the read, you'll notice that it returns the number of bytes that is read"... um is that the same as... public abstract int read() throws IOException Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If ...

82. how to create a file with a inputstream or outputstream .    forums.oracle.com

Ok, see i am using GWT(google web toolkit) as front end. user will add file from the front end. that file will be recived by the server. this recieved file is of type "fileitem". from fileitem i can get only input stream or byte array. i want to put this file in a temporary directory that is why i want to ...

83. OutputStream for encoder    forums.oracle.com

84. OutputStream problem    forums.oracle.com

Hi, I am using java comm API to send some cmd to a bluetooth device which is working fine if I turn on the device before I send the cmd. But if I try to send out cmd before the device has been turned on. The program would be stuck at g_os.write(sendCMD); code: CommPortIdentifier g_portId = CommPortIdentifier.getPortIdentifier(portname); g_sPort = (SerialPort)g_portId.open("test", 30000); ...

85. Java OutputStream (or other) into