StringInputStream?

do i use the StringInputStream class when i want to get a string from the inputstream?
eg.
Socket skt;
InputStream input;
StringInputStream sInput;
//get string input stream from socket
input = skt.getInputStream();
sInput = new StringInputStream(input);
String str = new String(sInput.readUTF());
System.out.println(str);

do i use the StringInputStream class when i want to
get a string from the inputstream?
eg.
Socket skt;
InputStream input;
StringInputStream sInput;
//get string input stream from socket
input = skt.getInputStream();
sInput = new StringInputStream(input);
String str = new String(sInput.readUTF());
System.out.println(str);No StringInputClass in java.
What u want to read and what u want to output? byte? text?

Similar Messages

  • Send redirect not working in IGETMarkupInterceptor 's OnIOFailure

    Hi
    I am trying to redirect the user to an error page (portal page not jsp) by using sendredirect to the " desktopURL+_pagelabel=error_pagename" in the onIOFailure method of IGETMarkupInterceptor implementation.
    Even though the sendredirect is there in the method it is not redirecting the user to the errorpage but showing the exception or no markup available message in the proxy portlet.
    This is what I am doing in the OnIOFailure ... The same code works in the IInitCookieInterceptor's OnIOFailure but here it is not ..
    public OnIOFailure onIOFailure(IGetMarkupRequestContext arg0,
                   IGetMarkupResponseContext arg1, Throwable arg2) {
              HttpServletRequest req = arg0.getHttpServletRequest();     
              String redirectURI = "/pocconsumerweb/appmanager/inter/my?_nfpb=true&_pageLabel=MP1_FederationConsumer_portal_page_19" ;     
    try {
              arg0.getHttpServletResponse().sendRedirect(redirectURI);                    
              catch (IOException e) { 
                        // TODO Auto-generated catch block
                        e.printStackTrace();
              return Status.OnIOFailure.HANDLED;
    Is it not allowed to do send redirect here or not possible ? Any workarounds ?
    Thanks in advance
    jesh

    Thanks Kevin
    I have done a work around to achieve the redirection from IGetMarkup. I am adding a javascript as markup to the response. Java script redirects the use to the required page onload of the markup.
    It is not a the rightway but this is how I was able to handle this scenario ....
    String errorpage = "<head><script>function redirectToError(){window.location = '../inter/mydesktop?_nfpb=true&_pageLabel=myerror_page';}</script></head>";
                        StringInputStream stringInputStream = new StringInputStream(errorpage);
                        arg1.setMarkupData(stringInputStream);
    Thanks
    Jesh

  • How to use XPath with Namespaces in the xml ?

    Hi all,
    I need to reference a certain Node in a Document using XPath notation.
    The problem is the the XML Document contains Namespaces inside it
    f.e.
    <xn:SubNetwork id="JRANM">
        <xn:VsDataContainer id="1">
           <xn:vsDataType>vsDataAreas</xn:vsDataType>
        </xn:VsDataContainer>
    </xn:SubNetwork >Using DOMXPath (from weblogic.xml.xpath)
      DOMXPath xPath = new DOMXPath("xn:SubNetwork/*");
      Set nodeset = xPath.evaluateAsNodeset(this.xmlRootElement);When I Iterate through the Set I can see it's empty.
    (On the other hand without namespaces everything is fine.)
    So how can I reference a Node that contains a namespace in it ?
    Thanks a lot
    Francesco

    We use the following class to perform XPath Queries on our XmlBean objects.
    Hope this helps,
    Craig
    import java.util.Set;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.apache.xmlbeans.XmlException;
    import org.w3c.dom.Document;
    import weblogic.xml.util.StringInputStream;
    import weblogic.xml.xpath.DOMXPath;
    * Class to encapsulate API specific (i.e. weblogic) XML functions
    public class XmlUtil {
         * Returns a set containing objects of type reflected in the query.<br/>
         * e.g.<br/>
         * /saur:tree/saur:treeNode[@label='My Reports']<br/>
         * Returns a Set of TreeNode objects<br/>
         * Sample Code: <br/>
         * <code>
         * Set set = XmlUtil.executeXPathQuery( myQuery, tree.xmlText());
         * for( Iterator iter = set.iterator(); iter.hasNext();) {
         *     TreeNode node = TreeNode.Factory.parse((Node)iter.next());
         *     // Do whatever...
         * </code>
         * @param query
         * @param xml
         * @return
        public static Set executeXPathSetQuery( String query, String xml) throws XmlException {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                StringInputStream in = new StringInputStream(xml);
                Document doc = builder.parse(in);
                DOMXPath xQuery =  new DOMXPath(query);
                return xQuery.evaluateAsNodeset(doc);
            catch(Exception x) {
                throw new XmlException("Error running XPath query", x);
    }

  • JAXB Validation Error

    Hi,
    Iam using JAXB. I get an validation error. When i try to marshal an object to XML. The code is simple as shown below
    1. Container.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://agi.com"
    xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://agi.com"
    elementFormDefault="qualified">
    <complexType name="ContainerType" abstract="true">
    <sequence>
    <choice>
    <element name="File" type="anyType" />
    <element name="Pen" type="anyType" />
    </choice>
    </sequence>
    </complexType>
    <element name="Container" type="tns:ContainerType" abstract="true" />
    </schema>
    2. Holder.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://agi.com"
    xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://agi.com"
    elementFormDefault="qualified">
    <include schemaLocation="Container.xsd"></include>
    <complexType name="HolderType">
    <complexContent>
    <restriction base="tns:ContainerType">
    <sequence>
    <choice>
    <element name="File">
    <complexType>
    <sequence>
    <element name="FileName"
    type="string">
    </element>
    <element name="Capacity"
    type="integer">
    </element>
    </sequence>
    </complexType>
    </element>
    <element name="Pen">
    <complexType>
    <sequence>
    <element name="Make"
    type="string">
    </element>
    </sequence>
    </complexType>
    </element>
    </choice>
    </sequence>
    </restriction>
    </complexContent>
    </complexType>
    <element name="Holder" type="tns:HolderType"></element>
    </schema>
    Main.java
    package test.client;
    import java.io.PrintWriter;
    import java.io.StringWriter;
    import java.math.BigInteger;
    import java.util.List;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    import javax.xml.bind.Validator;
    import test.vo.AnyType;
    import test.vo.Holder;
    import test.vo.ObjectFactory;
    import test.vo.HolderType.FileType;
    import test.vo.HolderType.PenType;
    import com.sun.xml.bind.StringInputStream;
    public class Main {
    public static void main(String s[]) throws Exception{
    JAXBContext ctx = JAXBContext.newInstance("test.vo" );
    ObjectFactory obj = new ObjectFactory();
    Holder input = obj.createHolder();
    FileType file = obj.createHolderTypeFileType();
    file.setCapacity( BigInteger.valueOf(35) );
    file.setFileName("Accounts");
    AnyType any = obj.createAnyType();
    List lst = any.getContent();
    lst.add(file);
    input.setFile(any);
    Marshaller marsh = ctx.createMarshaller();
    marsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
    new Boolean(true));
    marsh.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
    "http://agi.com");
    Validator validator = ctx.createValidator();
    validator.validate(input);
    StringWriter sw = new StringWriter();
    marsh.marshal(input, new PrintWriter(sw) );
    StringBuffer sb = sw.getBuffer();
    System.out.println(sb.toString() );
    This throws the following exception
    DefaultValidationEventHandler: [ERROR]: tag name "test.vo.AnyType" is not allowed. Possible tag names are: <test.vo.HolderType.FileType>
    Location: obj: test.vo.impl.HolderImpl@1cd8669
    Exception in thread "main" com.sun.xml.bind.serializer.AbortSerializationException: tag name "test.vo.AnyType" is not allowed. Possible tag names are: <test.vo.HolderType.FileType>
    at test.vo.impl.runtime.ValidationContext.reportEvent(ValidationContext.java:199)
    at test.vo.impl.runtime.ValidationContext.reportEvent(ValidationContext.java:166)
    at test.vo.impl.runtime.MSVValidator.childAsElementBody(MSVValidator.java:336)
    at test.vo.impl.runtime.MSVValidator.childAsBody(MSVValidator.java:292)
    at test.vo.impl.ContainerTypeImpl.serializeBody(ContainerTypeImpl.java:52)
    at test.vo.impl.HolderTypeImpl.serializeBody(HolderTypeImpl.java:30)
    at test.vo.impl.HolderImpl.serializeBody(HolderImpl.java:43)
    at test.vo.impl.runtime.MSVValidator._validate(MSVValidator.java:102)
    at test.vo.impl.runtime.MSVValidator.validate(MSVValidator.java:77)
    at test.vo.impl.runtime.ValidationContext.validate(ValidationContext.java:75)
    at test.vo.impl.runtime.ValidatorImpl.validate(ValidatorImpl.java:121)
    at test.vo.impl.runtime.ValidatorImpl.validate(ValidatorImpl.java:104)
    at test.client.Main.main(Main.java:63)
    However if i commentout the validation it works fine yeilding the
    following result
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Holder xsi:schemaLocation="http://agi.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://agi.com">
    <File>
    <FileName>Accounts</FileName>
    <Capacity>35</Capacity>
    </File>
    </Holder>
    Which look good conforming to the schema above
    It willbe helpful if someout could point out the mistake iam doing
    Please help
    Regards
    Agilan Palani

    I changed the code
    marsh.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,"http://agi.com Holder.xsd");
    to
    marsh.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,"http://agi.com E:/Agilan/Holder.xsd");
    But still the same error.
    I have validated the generated xml using XMLObjective. It says the generated xml is valid against the schema.
    I really dont know why the JAXB validation fails?
    Please help

  • Preserve single quote in text data.

    I have text data that is read into a BurrefedReader, some text contain single quoutes such as Ray's. When I retieve the data instead of seeing the single quote I see a square box replacing the single quote. What can I do in java to preserve the single quote?
    Thanks.

    Many thanks....here is my original code:
    public static String ClobToString(Clob cl) throws IOException, SQLException
    if (cl == null)
    return "";
    StringBuffer strOut = new StringBuffer();
    String aux;
    String aux2;
    BufferedReader br = new BufferedReader(cl.getCharacterStream());
    String ls =System.getProperty("line.separator");
    while ((aux=br.readLine())!=null)
    strOut.append(aux+ls);
    return strOut.toString();
    Here is the code with the encoding convertion:
    public static String ClobToString(Clob cl) throws IOException, SQLException
    if (cl == null)
    return "";
    StringBuffer strOut = new StringBuffer();
    String aux;
    String aux2;
    BufferedReader br = new BufferedReader(cl.getCharacterStream());
    String ls =System.getProperty("line.separator");
    while ((aux=br.readLine())!=null)
    strOut.append(aux+ls);
    StringInputStream st = new StringInputStream(strOut.toString());
    InputStreamReader inStreamReader=new InputStreamReader(st,"UTF-8");
    BufferedReader bufReader=new BufferedReader(inStreamReader);
    StringBuffer strOut2 = new StringBuffer();
    while ((aux2=bufReader.readLine())!=null)
    strOut2.append(aux2+ls);
    return strOut2.toString();
    I do thank you again for any help.

  • Error in  weblogic  portal jsp

    I copied the rss/rss_header.jsp file included in some weblogic shared library to my project and WorkSpace Studio says it contains errors, how is this possible since it came from its own library?(no modifications at all)
    the problem is that it cannot find this package weblogic.xml.util. and this class StringInputStream wich I think is in that package, what I need to know is which library or facet do I have to add into my project to avoid this error?

    this file is in weblogic.jar. You might have to edit the Weblogic System Libraries in workshop to include weblogic.jar
    Edit
    Right Click project - properties --> Java Build path --> Libraries -->Weblogic System Libraries --> if weblogic.jar isnt there , click edit and browse to weblogic .jar
    regards
    deepak
    Edited by: deepshet on Jun 24, 2009 9:15 AM

  • Creating a SOAP Request

    I'm using ancient technology (constraints imposed by the legacy application i'm working on) so hopefully there's someone who can help.
    i'm trying to create a SOAP message from an xml string thus:
          DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
          dbFactory.setNamespaceAware(true);
          DocumentBuilder documentBuilder = dbFactory.newDocumentBuilder();
          Document document = documentBuilder.parse( new StringInputStream( requestStr ) );
          DOMSource source = new DOMSource(document);
          MessageFactory msgFactory = MessageFactory.newInstance();
          SOAPMessage soapMessage = msgFactory.createMessage();
          SOAPPart part = soapMessage.getSOAPPart();
          part.setContent( source );
          soapMessage.saveChanges();and i get the following exception:
    javax.xml.soap.SOAPException: Unable to get header stream in saveChanges: SOAP exception while trying to externalize: Unable to create envelope from given source: org.apache.xerces.dom.DeferredDocumentImpl
    Any ideas are greatly appreciated.
    Thanks,
    Nilesh

    Hi Nilesh,
    Check that proper SOAP Message Structure is followed in the XML String(e.g. Element Names, NameSpace etc). Then try following code for initializing SOAPMessage from XML String. I am using this in number of applications and it works fine for me.
    // Initializing StringInputStream
    StringInputStream strInputStream = new StringInputStream( requestStr );
    // Getting New SOAPFactory
    MessageFactory factory = MessageFactory.newInstance ();
    // Initializing MimeHeaders, Use this for adding any Mime Headers in the SOAPMessage currently it is empty
    MimeHeaders mimeHeaders = new MimeHeaders ();
    // Initializing SOAPMessage with inputstream and mimeheaders
    SOAPMessage soapMessage = factory.createMessage (mimeHeaders, strInputStream );
    //TODO: Necessary Exception HandlingThanks,
    Tejas

  • Reader and InputStream

    I notice it is fairly easy to create a reader for an input stream.
       Reader reader = new InputStreamReader( in );However, I don't see any easy way to create an input stream from a reader.
       InputStream in = new ReaderInputStream( reader );Is there an obvious reason for this that I am missing? A reason why someone would never what to do this? Or is there an adapter class that I am just missing?
    As always, thanks in advance,
    R.

    Well, no not really. That's a very specific example (i.e. strings). Basically, I can read content from a variety of places -- the content could come as a ByteArrayInputStream, StringInputStream, FileInputStream and so on -- I won't know which. I use a reader to work with that input stream (possibly filtering it). Then I want to take this content and put it into a database as an InputStream. I can't just use the original input stream because it may have been filtered using a reader. I want to keep these as streams because, in the case that it is a FileInputStream, I don't want to have to load the entire stream into memory as a byte-array. Furthermore, the source content could be binary or text. I want to have two wrapper methods, one that took a Reader and one that took an InputStream. These would them write that data to the database, which is why I was wondering if there was an easy way to wrap a Reader with an InputStream (I already know the reverse is easy). Sounds like I need to introduce another layer of abstraction. Maybe a Content class tree that can get/set an InputStream.

Maybe you are looking for