How to convert OutputStream to String?

I'm trying to convert an outputstream to a String, but I'm not succeeding. Anyone any clues? Thx

they Were right.
But outpoutstream and inputstream just a "data"
if you want to see it, this may Help.
i try see from another java forum.
/* author : "Joe" <[email protected]> */
import java.io.*;
public class IOString {
private StringBuffer buf;
/** Creates a new instance of IOString */
public IOString() {
buf = new StringBuffer();
public IOString(String text) {
buf = new StringBuffer(text);
public InputStream getInputStream() {
return new IOString.IOStringInputStream();
public OutputStream getOutputStream() {
return new IOString.IOStringOutputStream();
public String getString() {
return buf.toString();
class IOStringInputStream
extends java.io.InputStream {
private int position = 0;
public int read() throws java.io.IOException {
if (position < buf.length()) {
return buf.charAt(position++);
else {
return -1;
class IOStringOutputStream
extends java.io.OutputStream {
public void write(int character) throws java.io.IOException {
buf.append( (char) character);
public static void main(String[] args) {
IOString target = new IOString();
IOString source = new IOString("Hello World.");
convert(target.getOutputStream(), source.getInputStream());
System.out.println(target.getString());
/** <CODE>convert</CODE> doesn't actual convert anything but copies byte
for byte
public static boolean convert(java.io.OutputStream out,
java.io.InputStream in) {
try {
int r;
while ( (r = in.read()) != -1) {
out.write(r);
return true;
catch (java.io.IOException ioe) {
return false;
Regs,
dedi mulyana

Similar Messages

  • How to convert Binary to String?

    Hi,
    How to convert Binary to String? Thank!

    Never ceases to amaze me how many people cannot
    accept any form of criticism whatsoever. How dothey
    get through the normal day? Do they pick fightswith
    everyone who says anything to them they don'tlike?
    Was this for me????Who are you calling a psycho??

  • How to convert byte into string

    can any tell me how to convert byte into string
    when im an debugging thid code in eclipse it shows the result in integer format instead of string but in command prompt it is showing result in string format..........plz help
    package str;
    import java.io.*;
    public class Testfile {
    public static void main(String rags[])
    byte b[]=new byte[100];
    try{
    FileInputStream file=new FileInputStream("abc.txt");
    file.read(b,0,50);
    catch(Exception e)
         System.out.println("Exception is:"+e);
    System.out.println(b);
    String str=new String(b);
    System.out.println(str);
    }

    Namrata.Kakkar wrote:
    errors: count cannot be resolved and Unhandled exception type Unsupported Encoding Exception.
    If i write an integer value instead of "count" then Unhandled exception type Unsupported Encoding Exception error is left.This is elementary. You need to go back to [http://java.sun.com/docs/books/tutorial/|http://java.sun.com/docs/books/tutorial/] .

  • Converting OutputStream to String

    This is a stupid question, but...How do you convert OutputStream to a String. For example i get output stream by:
    OuputStream os = process.getOutputStream();
    Now I want to convert that stream into a string. How would I do that? How do I use the write() method? I don't have to write the stream anywhere, I just need it in the form of a string. When i simply use os.toString(), it converts the stream to some encrypted code. I need to convert it so the stream is readable.
    Thanks.

    import java.io.*;
    class PipingDemo {
        public static void main(String[] args) throws Exception {
            final PipedInputStream inPipe = new PipedInputStream();
            PipedOutputStream outPipe = new PipedOutputStream(inPipe);
            OutputStreamWriter osWriter = new OutputStreamWriter(outPipe);
            PrintWriter out = new PrintWriter(osWriter);
            Thread thread = new Thread(new Runnable() {
                public void run() {
                    try {
                        BufferedReader in = new BufferedReader(new InputStreamReader(inPipe));
                        String line;
                        StringBuffer output = new StringBuffer();
                        while((line = in.readLine()) != null) {
                            output.append(line);
                            output.append(System.getProperty("line.separator"));
                        in.close();
                        System.out.println(output.toString());
                    } catch (IOException e) {
                        e.printStackTrace();
            thread.start();
            out.write("Shama Lama rama rama rama ding dong");
            out.write("\nYou put the ooh mau mau oh oh oh oh");
            out.write("\nBack into my smile, child");
            out.write("\nThat is why (That is why)");
            out.write("\nYou are my sugar dee dee doo");
            out.close();
    }

  • How to convert number to string in java

    hi how can i convert number to string in java
    something like
    public void Discription(Number ownerName){
    String.valueOf(ownerName);Edited by: adf009 on 2013/04/08 7:14 PM

    Yet another way of doing it is: ownerName.toString().
    If you are working in and IDE such as Netbeans or Eclipse, type a period after the object name. Wait a second or so. Eclipse/Netbeans Intellisense will show you a list of functions that object provides that you can choose from. toString() is one of them.

  • How to convert LongRaw to String when querying using DB Adapter?

    Hi All,
    How do we use a DB Adapter to query on LONG Raw data? Is there a way to implicitly convert data to a string before returning the resultSet?
    JDev: 11.1.1.4
    Regards.

    Hi,
    LONG RAW data will be retrieved as base64binary, you can use and Embed Java to convert it back to string.
    How to convert String to base64Binary in BPEL process
    Or you can use doTranslateFromNative oracle extension function, you will need a NXSD template to use it.
    http://docs.oracle.com/cd/E15523_01/integration.1111/e10224/bp_appx_functs.htm#CJACABGA
    Cheers,
    Vlad

  • How to Convert JTextArea to String

    How would i convert JTextArea to string?

    elaborate, whats RTFAPI? I searched for it and got
    nothing.Since I'm not quite sure if you are being sarcastic, that translates to "read the f*cking application programmer interface". :)

  • How to convert integer to string?

    for example :
    int num = 1;
    String num_str;
    how to convert the value of num variable to string .

    have u ever checked the documentation of WTK
    one method called valueOf
    will help u
    alpesh

  • How to convert Localized formatted String in Amount?

    Hello All,
    I have once scenario where I need to convert localized string amount to parse and make it long amount.
    Example: In russia, people write 1000 as "1 000".
    Now what I need to do is to parse this "1 000" and get 1000.
    Is there any way in java, which can identify if the particular string is localized price in some Locale and give us the normal long output?
    Thanks,
    Jenish

    The char after the 1 of 1 000 is not a space (value: 32) it's a no-break space (value 160). Copy this line and paste it into your code:System.out.println(nf.parse("1&#0160;000"));And please read the announcement(s) at the top of the forum listing, they're there for a purpose. Then edit your post and format the code correctly.
    db
    edit Dang, the forum parsing (or maybe the browser rendering) converts that to a normal space :( Trying again... and again ...
    No, it appears both &amp;nbsp; and &amp;#0160; are corrupted to a &amp;#0032; no matter how I try it. One more try, with pre tags instead of code tags
    System.out.println(nf.parse("1 000"));Nope. With noformat
    {noformat}System.out.println(nf.parse("1 000"));{noformat}
    On a Windows computer, you can type the no-break space using Alt-0160 or copy it from the Character Map. Other than that, here's my best attempt to illustrate what's going on:NumberFormat nf = NumberFormat.getInstance(new Locale("ru", "RU"));
    try {
      System.out.println("1 000".equals(nf.format(1000))); // false
      String thousand = "1" + ((char) 160) + "000";
      System.out.println(thousand); // looks like 1 000
      System.out.println(nf.parse(thousand)); // 1000
    } catch (ParseException e) {
      e.printStackTrace();
    }Edited by: Darryl Burke

  • How to convert filenames into strings

    im listing a lists of files
    using the method listFiles() which returns me data of type File which are actually
    all files in the dir.
    may i know how do i convert the filenames returned to become strings
    so that i can manipulate the filenames as string format instead of file format?
    thanks for any help suggested!

    Im encountering a problem now before i can test the method...
    This the current problem i had :
    i only showed part of the codes here:
    File[] listing = Dir.listFiles();
    String[] lists;
    for (int i=0; i < listing.length; i++)
    lists[i] = new String(listing.getName());
    out.print(lists[i] + "<br>");
    The error i had:
    variable lists might not have been initialized
    lists[i] = new String(listing[i].getName());
    ^
    1 error
    I forgot how to deal with String array...
    I declare as String[] lists; coz i do not know the size of the array...
    how do i assign the filenames to strings?
    Please kindly help..thanks a lot!

  • How to convert Date to String

    Hi All,
    I have a dimension member in my classic plannnig application whose datatype is Date,
    Now i want to use that member inside the following function:
    @TODATE(<date format goes here> , <date string goes here>);
    e.g
    @TODATE("mm-dd-yyyy" , "Dimension Member Name");
    Now the second parameter to this function is of string type, whereas the data type of my member is "Date", so is there any way to convert this date to string?
    Notes:-
    I am using the above script inside the member formula.
    I run the code with some static value e.g.
    @TODATE("mm-dd-yyyy" , "01-12-2011"); and it works quite fine so i am pretty much sure that issue is related to incompatible data types.

    Have a look at the following post it should give you an idea - Re: @DatePart formula produces constant result
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • How to Convert Cluster to String

    Here is a VI to convert any data to a String, and the VI to convert the String back to a Variant.  Use the Variant to Data function to convert back to your data type.  I use LV 8.2, please rate if it helped you. Thanks.
    -Branson
    Solved!
    Go to Solution.
    Attachments:
    data-string-data labview 8.2.PNG ‏6 KB
    to_String 1.vi ‏19 KB
    String_to 1.vi ‏21 KB

    OK. Can open them now.
    From a programmatic perspective and usability perspective, what do you see as the main advantage of this method as opposed to using the Flatten To String and Unflatten From String functions without going through an intermediate variant? Or, perhaps, the Flatten to XML/Unflatten from XML functions. In other words, what are the pros and cons of your method as opposed to this method:
    One clear advantage of your method clearly is that you do not need to wire in the data type, as you need to do with the Unflatten From String function. Were you addressing other concerns?
    Message Edited by smercurio_fc on 10-12-2008 11:04 AM
    Attachments:
    Example_VI_BD.png ‏3 KB

  • How to convert a delimited string to XML?

    Hi there,
    Please help me to convert a pipe delimited string into XML, e.g.
    string -------SubName:abc|SuvValue:123|
    required XML:
    <ROWS>
    <ROW>
    <SubName>abc</SubName>
    <SubValue>123</SubValue>
    </ROW>
    </ROWS>
    or
    string -------abc|123|
    required XML:
    <ROWS>
    <ROW>
    <SubName>abc</SubName>
    <SubValue>123</SubValue>
    </ROW>
    </ROWS>
    -----i am trying to first parse the string into a table type and then using the DBMS_XMLGen.getXML function but unable to get values from table type...
    any prompt response is highly appriciated...
    Regards, Hassan

    Hi Hassan,
    If your version supports it (ie 10gR2 and upwards), you can use XQuery to directly parse the string and generate the XML :
    SQL> SELECT XMLQuery(
      2   '<ROWS>
      3    <ROW> {
      4     for $i in ora:tokenize($str,"\|")
      5     return
      6      if ($i) then element {substring-before($i,":")} {substring-after($i,":")}
      7      else ()
      8   } </ROW>
      9   </ROWS>'
    10   passing sys_xmlgen('SubName:abc|SubValue:123|') as "str"
    11   returning content
    12  ).getClobVal()
    13  FROM dual;
    XMLQUERY('<ROWS><ROW>{FOR$IINO
    <ROWS><ROW><SubName>abc</SubName><SubValue>123</SubValue></ROW></ROWS>
    Each element is built based on its name from the input string.

  • How To Convert XML into String?

    Hi,
    I have a requirement in which I need to convert the data from XML file to string.
    E.g.
       <Drawing>
          <DrawingSpecification>
             <Header>
                <SoldTo>SDN</SoldTo>
                <SoldToName>SAP</SoldToName>
                <Date/>
                <Manager>CEO</Manager>
                < Plant>INDIA</Name>
                <Items>
                   <Item>
                       < MaterialNumber>MatNum12</ MaterialNumber>
                       <ProductNumber>ProName12</ ProductNumber>
                   </Item>
               </Items>
               < ClientId>ClientID123</ ClientId>
               <FileName>FileName123</FileName>
               <Type/>
               < TemplateName/>
          </DrawingSpecification>
          <Image contentType=""/>
       < /Drawing>
    Output should be like:
       < File>
          < Content> SDN SAP CEO INDIA MatNum12 ProName12 ClientID123 FileName123</Content>
       < /File>
    Please provide solution for the same.
    Thanks,
    Abhishek.

    what about something like this
    package test;
    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    public class Test {
         public static void main(String args[]) throws Exception {
              DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
              DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
              Document doc = docBuilder.parse(new File("test.xml"));
              StringBuffer buffer = new StringBuffer();
              appendChildren(buffer, doc.getChildNodes());
              System.out.println(buffer.toString());
         private static void appendChildren(StringBuffer buffer, NodeList list) {
              for (int i = 0; i < list.getLength(); i++) {
                   Node node = list.item(i);
                   if (node.getNodeValue() != null) {
                        if (node.getNodeValue().trim().length() > 0) {
                             buffer.append(node.getNodeValue()).append("|");
                   appendChildren(buffer, node.getChildNodes());
    ...btw: IMHO the use of this forum is to get an answer to an particular question - not to ask for complete solutions - create the solution yourself an ask if you are stuck somewhere (with a bit of research (google) it is not hard to find a solution for your problem)
    regards franz
    ...close thread if question is answered

  • How i convert boolean to string ?

    which function do it ?
    thanks

    There is no standard way of converting a boolean to a string, so there is no function to do this (a "True" boolean string can be "1", "-1", "Yes", "T", "True", etc.). You can do this by using a case structure or the Select function from the comparison palette (insert a boolean and output whichever string you want). You can convert it to a variant or to a number and then to a string or you can type cast it directly to a string. In short, it depends on what string you want, but the easiest way is by using the Select function.
    This is really a rather basic question. To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here, here, here, here and here are a few you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
    In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).

Maybe you are looking for

  • Plant specific fields in the material master for product move

    Hi, SAP gurus, My scenario is we are moving a existing product in US plant to Brazil plant. What are the fields in the material master that are specific to a plant that will change. For ex MRP controller will change from plant to plant. Like that can

  • Accounting document not cleared when billing document is cancelled.

    Hi, In ECC 6.0 when we cancel a billing document through vf11 in vfo3 we find the status as accounting document not cleared. The general process is manually going to f-23 and clear customer line items of that invoice. After doing this the status beco

  • Elements 9, DSLR H.264 - What codec is best to edit with & highest quality?

    Hello All, I have quite a bit of DSLR footage I recently shot using a Canon 5d.  I have Adobe Premiere Elements 9 and it really chokes down the system.  I have a PC with i7 and 8 gigs of RAM. What would be the best file format to convert the H.264 fo

  • No Video just Audio Monitor Green

    When i Play Video from iTunes Store there is a Green/Pink Monitor Audio is perfekt

  • Hard disk fail. unintelligible error code.

    Hi:  i have a non-booting  hp G62 -b20SA. The in-built diagnostics give me a Fail code:  GLQJK9-5LM681-9XLO3F-6OT303   and a Product Id: XF390EA#ABU    and   HardDisk 1   and a web URL.   What does this code mean?.    I have been round and round the