How to remove characters/lines from the beginning of an InputStream

Hi,
I have a program which receives several InputStreams. From each of these streams I have to remove 2 lines from the beginning. After the lines are removed, all the streams are combined to one with SequenceInputStream and read in one chunk. Is there an easy/simple way of doing this?
One option I thought would be to read the char by char until 2 end of line chars have been detected and then read the rest of the data to a buffer. And the create a ByteArrayInputStream out of this buffer. Problem with this approach is, that the amount of data can be large, so putting all the data in to memory might cause problems.
Another option is to use BufferredInputStream and use the readline() method twice to get rid of the lines that are not needed. After this I would write the data to some output stream, which is then converted back to input stream. Propably would work, but sound too much of work for a simple thing like this. There has to be better way.
To make it simple, what I need is a method that looks like the following, or something similar
*  Removes n number of lines from the beginning of a InputStream.
*  @param is InputStream where the lines are removed
*  @param numberOfLines int value to indicate how many lines whould be removed
*  @return InputStream where lines have been removed.
public InputStream removeLines(InputStream is, numberOfLines);Thanks.

Here's the code, feel free to use it. Comments are also welcome.
public InputStream removeLinesFromTheBeginning(InputStream is, int numberOfLines) throws IOException
          char c = 'c';
          int i = 0;
          for(int n = 0 ; n < numberOfLines ; n++)
               do
                    c = (char)is.read();
                    System.out.print(c);
                    if(c == (char)-1)     // end of stream reached before any newline characters were found.
                         return null;
                    i++;
               while(c != '\n');
               System.out.println();
               System.out.println("Characters removed:" + i);
               System.out.println("n: " + n);
               i = 0;
          return is;
     }Edited by: dave_spaghetti on Jun 16, 2009 5:42 AM
Fixed a bug.

Similar Messages

  • How to remove available downloads from the list

    how to remove available downloads from the list without it resuming when i open itunes or check for available downloads?

    There is not a way to remove them from the list.  Just let them download, and then delete them from your library when they are done.

  • How to remove SD Card from the Card Reader slot - Satellite A100?

    Hi,
    Is there anyone to help me? I inserted a 64 MB SD card in the card reader slot of my Toshiba A100 model. It's the first time i have inserted the card. The card is inside the slot. I can not take it out! I don't have any idea how to remove the card from the card reader slot. I can see the contents of my SD card, can open the files too. But how to remove it out from the slot. Please help me giving your idea to remove the card out from the slot.
    Arjun

    Hi
    In my knowledge the SD card slot doesnt has a any additional helps like the PCMCIA slot to remove the card.
    You have to remove it simply. Try to grab the card and move it out. You can try to use the pair of tweezers. Maybe it helps

  • How to remove unused objects from the webcatalog In OBIEE11g

    Hi,
    I want to delete unused objects from obiee11g catalog, i know in obiee10g it's working fine (i.e: we can do it via manage catalog then delete the unused objects) is there any way to do it automatically like RPD utility --->removing unused objects from Physical layer in RPD
    fyi: I don't want to delete manualy. i need somethink like button/link to find unused objects(report,filter,folder..etc) from my obiee11g catalog.
    Thanks
    Deva
    Edited by: Devarasu on Nov 29, 2011 12:06 PM
    Edited by: Devarasu on Nov 29, 2011 3:15 PM

    Hi,
    Checked with Oracle Support team and confirmed below points
    --> incorporated into the Current product and consider as BUG it may resolve future release
    --> Currently there isnt any automatic method to remove the unused objects like reports, filters,folder etc from catalog.
    Treated as Bug
    Bug 13440888 - AUTOMATICALLY REMOVE OF UNUSED CATALOG OBJECTS FROM WEBCATALOG
    FYI:
    SR 3-4984291131: How to remove unused objects from the webcatalog in obiee11g
    Thanks
    Deva

  • HT2500 Does anyone know how to remove a group from the address panel in mail?

    Does anyone know how to remove a group from the address panel in mail?

    I haven't seen too many questions like this on this forum.  Did you also try the photoshop forums?

  • [svn] 4694: Don't remove text lines from the container if it isn' t the container the lines were added to.

    Revision: 4694
    Author: [email protected]
    Date: 2009-01-27 14:35:21 -0800 (Tue, 27 Jan 2009)
    Log Message:
    Don't remove text lines from the container if it isn't the container the lines were added to. When there is a state change the displayObject can be switched out from under the TextGraphic and TextBox.
    QE Notes: need to add tests - will attach my test program to bug
    Doc Notes:
    Bugs: SDK-18923
    Reviewers: Gordon
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-18923
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/graphics/graphicsClasses/TextBlockCompose r.as
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/graphics/graphicsClasses/TextFlowComposer .as

    Yup, you guys pointed me in the right direction.
    I changed my adjustmentListener to the following:
    JScrollBar scrollBar = (JScrollBar) e.getSource();
    int endLoc = document.getLength();
    try {
        Rectangle end = outputArea.modelToView(endLoc);
        if (end != null) {
            int n = scrollBar.getValue() + scrollBar.getVisibleAmount();
            boolean locked = (end.y >= n && n <= (end.y + end.height));
    } catch (BadLocationException ex) {
    }By comparing scrollbar position with the visible rectangle of the end of the document, I can now easily tell if the user has moved the tracker back or not.
    To go to the next step of automatically pausing scrolling whenever the user is moving the slider back, I also had to disable the automatic scrolling performed by DefaultCaret. Because there was no way to tell if the user was scrolling or if the output was adjusting from the adjustmentListener, I also had to flag whenever I was autoscrolling.
    The end result is a JTextPane that can be appended to at all, and locked by the user by using the slider. If new data arrives, the window is not scrolled, and any text selection the user has is not cleared. Perfect!

  • How to remove empty lines from xml files after removing nodes from document

    <pre>
    Hi
    <b>i have xml document, which is shown below
    after removing some nodes from the document ,i am getting empty lines in place of removed nodes,how to resolve this and get the proper xml document without any errors</b>
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE Message SYSTEM "TRD01.dtd">
    <Message>
    <Header>
    <CounterPartyType>CLIENT</CounterPartyType>
    <CreationTime>20134455</CreationTime>
    <ErrorCode>363 </ErrorCode>
    <ErrorEnterPriseId>N</ErrorEnterPriseId>
    <ErrorStatus>1</ErrorStatus>
    <ErrorSystemId>STL</ErrorSystemId>
    <ErrorTimes>31</ErrorTimes>
    <MessageType>T</MessageType>
    <RecipientEnterpriseId>N</RecipientEnterpriseId>
    <RecipentSystemId>EXM</RecipentSystemId>
    <Remarks>REMARSK</Remarks>
    <SenderEnterpriseId>N</SenderEnterpriseId>
    <SenderSystemId>TR</SenderSystemId>
    </Header>
    </Message>
    <ErrorCode>363 </ErrorCode>
    <ErrorEnterPriseId>NIHK</ErrorEnterPriseId>
    <ErrorStatus>1</ErrorStatus>
    <ErrorSystemId>STL</ErrorSystemId>
    <ErrorTimes>31</ErrorTimes>
    XPathExpression expression5 = xpath.compile(xmlpath5);
    Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
    Node node5 = (Node) result5;
    node5.getParentNode().removeChild(node5);
    XPathExpression expression6 = xpath.compile(xmlpath6);
    Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
    Node node6=(Node) result6;
    node6.getParentNode().removeChild(node6);
    XPathExpression expression7 = xpath.compile(xmlpath7);
    Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
    Node node7=(Node) result7;
    node7.getParentNode().removeChild(node7);
    doc.normalize();
    doc.normalizeDocument();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    t.setOutputProperty(OutputKeys.METHOD,"xml");
    t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    the xml output i am getting is
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Message>
    <Header>
    <CounterPartyType>CLIENT</CounterPartyType>
    <CreationTime>20134455</CreationTime>
    <MessageType>TRD01</MessageType>
    <RecipientEnterpriseId>N</RecipientEnterpriseId>
    <RecipentSystemId>STL</RecipentSystemId>
    <Remarks>REMARSK</Remarks>
    <SenderEnterpriseId>N</SenderEnterpriseId>
    <SenderSystemId>T</SenderSystemId>
    </Header>
    </Message>
    <b>could you please let me know how to avoid empty lines in the xml doucment output</b>
    this is the method i am using to get the result
    public void ValidateRecord(String xml){
    try{
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = factory.newDocumentBuilder();
    //parse file into DOM
    /*DOMParser parser = new DOMParser();
    parser.setErrorStream(System.err);
    parser.setValidationMode(DTD_validation);
    parser.showWarnings(true);*/
    System.out.println ("HI THIS xml is validation "+xml);
    Resolver res = new Resolver();
    db.setEntityResolver(res);
    Document doc = db.parse(new InputSource(new StringReader(xml)));
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xpath = xpf.newXPath();
    // XPathExpression expression = xpath.compile("//A/B[C/E/text()=13]");
    String xmlpath="/Message/Header/CounterPartyType/text()";
    String xmlpath1="/Message/Header/RecipentSystemId/text()";
    String xmlpath2="/Message/Header/ErrorSystemId/text()";
    XPathExpression expression = xpath.compile(xmlpath);
    XPathExpression expression1 = xpath.compile(xmlpath2);
    Object result = expression.evaluate(doc, XPathConstants.NODE);
    Object result1 = expression1.evaluate(doc, XPathConstants.NODE);
    Node node = (Node) result;
    Node node1 = (Node) result1;
    System.out.println("the values of the string is " +node.getNodeValue());
    System.out.println("the values of the string is " +node1.getNodeValue());
    // for (int i = 0; i < nodes.getLength(); i++) {
    //System.out.println(nodes.item(i).getNodeValue());
    // CAHNGING THE RECEIPENT NODE
    XPathExpression expression2 = xpath.compile(xmlpath1);
    Object result2 = expression2.evaluate(doc, XPathConstants.NODE);
    Node node2 = (Node) result2;
    System.out.println(node2);
    node2.setNodeValue(node1.getNodeValue());
    System.out.println(node2);
    //removing the nodes from document
    String xmlpath3="/Message/Header/ErrorCode";
    String xmlpath4="/Message/Header/ErrorEnterPriseId";
    String xmlpath5="/Message/Header/ErrorStatus";
    String xmlpath6="/Message/Header/ErrorSystemId";
    String xmlpath7="/Message/Header/ErrorTimes";
    XPathExpression expression3 = xpath.compile(xmlpath3);
    Object result3 = expression3.evaluate(doc, XPathConstants.NODE);
    Node node3 = (Node) result3;
    node3.getParentNode().removeChild(node3);
    XPathExpression expression4 = xpath.compile(xmlpath4);
    Object result4 = expression4.evaluate(doc, XPathConstants.NODE);
    Node node4 = (Node) result4;
    System.out.println("node value");
    System.out.println(node4.getParentNode().getNodeName());
    node4.getParentNode().removeChild(node4);
    XPathExpression expression5 = xpath.compile(xmlpath5);
    Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
    Node node5 = (Node) result5;
    node5.getParentNode().removeChild(node5);
    XPathExpression expression6 = xpath.compile(xmlpath6);
    Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
    Node node6=(Node) result6;
    node6.getParentNode().removeChild(node6);
    XPathExpression expression7 = xpath.compile(xmlpath7);
    Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
    Node node7=(Node) result7;
    node7.getParentNode().removeChild(node7);
    // Node b13Node = (Node) expression.evaluate(doc, XPathConstants.NODE);
    //b13Node.getParentNode().removeChild(b13Node);
    doc.normalize();
    doc.normalizeDocument();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    t.setOutputProperty(OutputKeys.METHOD,"xml");
    t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    t.transform(new DOMSource(doc), new StreamResult(System.out));
    catch (Exception e) {
         e.printStackTrace();
    System.out.println(e.getMessage());
    </pre>
    Edited by: user12185243 on Apr 6, 2013 6:38 AM
    Edited by: user12185243 on Apr 6, 2013 6:41 AM
    Edited by: user12185243 on Apr 6, 2013 6:43 AM
    Edited by: user12185243 on Apr 6, 2013 6:45 AM
    Edited by: user12185243 on Apr 6, 2013 9:00 AM

    either this way we can do this
    1)
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    <b> factory.setIgnoringElementContentWhitespace(true); </b>
    DocumentBuilder db = factory.newDocumentBuilder();
    or
    2)
    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult sr = new StreamResult(sw);
    t.transform(new DOMSource(doc), sr);
    String xml1 = sw.toString().trim();
    <b> xml1=xml1.replaceAll("\\s",""); </b>
    System.out.println(xml1.trim());

  • Any hints of how to exclude these lines from the following BEx output?

    Hi,
    I have a BEx report which outputs the following shipment activities, showing Doc and Items numbers, Requested and Received dates, actual and PO quantities.
    DocNoItmNoReqDate-RcvdDate-PO_Qty-Act_Qty---TB%
    1101-----5--12/10/05-12/5/05020--
    80
    1101-----5--12/10/05#00--80
    1101-----5--12/10/05#200--
    80
    1101-----7--12/10/05-12/5/05030--
    50
    1101-----7--12/10/05-12/8/0505--
    50
    1101-----7--12/10/05#00--50
    1101-----7--12/10/05#350--
    50
    Somehow, I am getting some activity lines which I do not understand but do not want in the output. Those are the lines which show u201CPO_Qty = 0 AND Act_Qty = 0 at the same time.u201D i.e. the highlighted lines.
    Any hint on how to eliminate the highlighted lines from the output?
    I played with calculated key figures but could not reason it out.
    Thanks

    DocNoItmNoReqDate-RcvdDate-PO_Qty-Act_Qty---  Formula                        TB%                                                                               
    PO QTY + ACT QTY
    1101-----5--12/10/05-12/5/05020-----               20                        -
    80
    1101-----5--12/10/05#00--                 0                         -80
    1101-----5--12/10/05#200-----                  20                     -
    80
    1101-----7--12/10/05-12/5/05030-----                30                      -
    50
    1101-----7--12/10/05-12/8/0505--
                    5                         -
    50
    1101-----7--12/10/05#00-----                  0                         -50
    1101-----7--12/10/05#350-----                 35                        -
    50
    Create Conditions over the Formula. Since the sum would be always 0 only when both the KF's are zero I think you can create condition over this formula.
    Would this help?
    Regards
    VJ

  • HT2905 How to remove duplicate songs from the iPhone when the duplicates are not listed in the iTunes library on the computer.

    How can I remove duplicate songs from the iPhone4. The duplicates are not listed in the computer iTunes library.

    The simplest thing may be to back-up and then restore the iPhone. If you don't fancy that then remove all media that is currently synced to it, then double check and manually remove any media that remains on the device, before reselecting your sync options.
    If you've been manually managing the device and your library doesn't contain copies of all your media then see Recover your iTunes library from your iPod or iOS device.
    tt2

  • Veeam - How to remove a drive from the rotated hard drive media pool

    Does anyone know of a way to remove a drive from the media pool of the rotated drive media repository?
    I accidentally added one to the repository and now I want to get it out of there so Veeam Backup & Replication  does not try to backup to a drive that is normally full.
    This topic first appeared in the Spiceworks Community

    Hi Frank, and a warm welcome to the forums!
    There still is that paper clip hole, but on some G4s you have to remove the faceplate or even drive to do it.
    Does it boot into Open Firmware with CMDOption+of ?
    http://docs.info.apple.com/article.html?artnum=42642
    Boot into Open Firmware and eject If you have a Mac that will not startup properly and has a stuck disc, try booting into Open Firmware by holding down Command, Option, O key and F key during startup. After booting into Open Firmware, type the command eject-cd.

  • How to remove new line from string

    I have a string say following
    String line = "one\ntwo\nthree";Now i am trying to remove new line from string. For this i did following
    String txt = line.replaceAll("\\n","");But i see still new line is occuring. Is it correct way. Please advice me.

    Ok. I was just using \n instead of \r\n. And i am in windows. I will give a try with \r\n
    Ok i tried using following , but it doesnt work.
    line = line.replaceAll("\\r\n","");Am i missing anything here. Please guide me.
    Edited by: ArpanaK on Oct 8, 2007 4:44 PM

  • How to remove blank lines in the end of list .

    hi,
    in a complex report ,when there are only 20 pages,and linecount is 65(2) ,in the last page only 27 lines are filled and data is completed.then blank lines are printing from 27th line to 63 line.then end of page is triggering.
    so plz help me how to remove the blank lines here and immediately print the endof page.

    Hi,
    will this work for you.
    SET BLANK LINES OFF.
    These statements allow you to specify whether you want to output blank lines or not. Use SET BLANK LINES ON to output blank lines or SET BLANK LINES OFF to suppress them.
    Regards
    Viswanath Babu

  • How to remove namespace link from the output XML

    i have to remove 'xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions"' (namespace) from the output xml file which is generated from the BIP. I need my output XML file without that namespace link, this namespace link is coming for each element.
    Anybody know how to do that please help.
    output xml file
    <?xml version="1.0" encoding="UTF-8" ?>
    <Reports version="2.00">
    <deliveryNote xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions">
    <subjectId />
    </deliveryNote>
    <deliveredReports xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions">
    <referDate>[Delivery note->H4]</referDate>
    </deliveredReports>
    <simpleReports xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions">
    <numberOfReports>2</numberOfReports>
    <nReport>
    <reportName>Xyz</reportName>
    <reportVersion>1.0</reportVersion>
    <observations>
    <numberOfObservations>15</numberOfObservations>
    <columnObservation>
    <y>9</y>
    <rO>
    <x>14</x>
    <o>11</o>
    <o>21</o>
    <o>121</o>
    </rO>
    </columnObservation>
    </observations>
    </nReport>
    </simpleReports>
    </Reports>
    my xslt file
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions" >
    <xsl:output method="xml" encoding="UTF-8"/>
    <xsl:template match="/">
         <xsl:element name="Reports">
              <xsl:attribute name="version">2.00</xsl:attribute>
                   <deliveryNote>
                        <subjectId></subjectId>
                        </deliveryNote>
                   <deliveredReports>
                        <referDate>[Delivery note->H4]</referDate>
                   </deliveredReports>
                   <simpleReports>
                        <numberOfReports>2</numberOfReports>
                        <nReport>
                                  <reportName>Xyz</reportName>
                                  <reportVersion>1.0</reportVersion>
                                       <observations>
                                       <numberOfObservations>15</numberOfObservations>
                                       <columnObservation>
                                            <y>9</y>
                                            <rO>
                                                 <x>14</x>
                                                      <xsl:for-each select="TEST_XML/LIST_R1/R1">
                                                           <o><xsl:value-of select="xdoxslt:lpad(COL1,10,' ')"/></o>
                                                      </xsl:for-each>
                                            </rO>
                                       </columnObservation>
                                       </observations>
                             </nReport>
                        </simpleReports>
              </xsl:element>
    </xsl:template>
    </xsl:stylesheet>

    Please post the same in BI Publisher forum
    BI Publisher
    Thanks,
    Vino

  • OSB: how to remove soap envelope from the $body

    Hi,
    In Assign activity when i assign: xquF1:url-decode(fn-bea:serialize($body),"UTF-8") = variable1,i am getting:
    $variable1 =
    <soap-env:Body      xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
         <MESSAGE>
    <aa>12</aa>
    <bb>34</bb>
    </MESSAGE>
    </soap-env:Body>
    How should i remove 'soap-env:Body' from the above xml. I need only:
    $variable1 =
         <MESSAGE>
    <aa>12</aa>
    <bb>34</bb>
    </MESSAGE>
    Kindly advise how to acheive the same.
    Thanks in advance.
    Edited by: user9223904 on Apr 17, 2013 2:25 AM
    Edited by: user9223904 on Apr 17, 2013 2:26 AM

    just use $body/* and you will have what u wanted.

  • How to remove -ve sign from the deduction wagetype in payslip

    Hi Experts,
    Plz tell me how i can remove the -ve sign from the deduction column in
    the Payslip.
    Regards
    TS

    Hi ,
    Do you just have to show the sign different in payslip and the RT .
    Coz what it seems is that the RT is having a negative WT , so in order to make it positive you goto
    PE51 , enter the form you are using and change the cumulation id for deduction wage type .
    Hope this helps.
    Regards,
    SureshP

Maybe you are looking for

  • GR/IR clearing account change for materials

    Dear all we need separate GR/IR clearing account for two materials  from April, 2008,as these materials has open PO and unrestitected stock (in MMBE), Please let me know whether we need to have new material code , one more thing the valuation class w

  • Abstract method versus static and non-static methods

    For my own curiosity, what is an abstract method as opposed to static or non-static method? Thanks

  • Lose internet when plugging into switch

    I am perplexed why I can create a wireless network with my airport extreme and have great internet connectivity through my cable company, but when I plug the airport into a switch to distribute the internet through out my office the internet immediat

  • First tab will not close and address bar in tab does not update.

    The first tab and its address bar are not working as expected. I am unable to close the first tab using the close icon on the tab or by selecting close tab from right click menu. I also find that the address bar when displaying the first tab does not

  • Customizing af:query component?

    Hello friends, Is it possible to customize af:query component. For example i need to move "search", "reset","save" buttons to the toolbar of the component and change the background of the toolbar. Also i have a request to hide that "+/-" thing which