Strange behaviour of StringBuilder. Does not append the last char buffer.

Below is the source code I am using to read a .gz file and convert it into plain text. I am using StringBuilder to store the whole plain text as a string and also writing the plain text to a file on disk. The writing on disk works perfectly fine, but for some weird reason, the StringBuilder leaves out the last part of the file (run it once and you'll see what I mean), when in fact both the StringBuilder and the OutputStreamWriter get their data from the same while loop.
import java.util.zip.GZIPInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class ProblemInStringBuilder
public static void main(String args[]) throws Exception
String inFilename, outFilename;
inFilename = "somefile.gz"; outFilename = "unzipped file.txt";
GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(inFilename));
InputStreamReader myInputStreamReader = new InputStreamReader(gzipInputStream);
OutputStream out = new FileOutputStream(outFilename);
OutputStreamWriter myOutputStreamWriter = new OutputStreamWriter(out);
int len;
char[] charBuf = new char[1024];
StringBuilder builder = new StringBuilder();
while ((len = myInputStreamReader.read(charBuf)) > 0)
builder.append(charBuf);
myOutputStreamWriter.write(charBuf,0,len);
gzipInputStream.close();
myInputStreamReader.close();
myOutputStreamWriter.close();
System.out.println(builder); // <-- problem here. Leaves out the last part of the file.
}

builder.append(charBuf);
builder.append(charBuf, 0, len);From this error it seems to me you are getting extra characters at EOF (and possibly elsewhere), not missing characters.
gzipInputStream.close();
myInputStreamReader.close();Remove the first of those. The second one closes them both.

Similar Messages

  • Photoshop CS does not append the extension to the filename

    Hi there.
    My Photoshop CS does not append the extension to the filename, when I save with Save as..., so it save all the files as .psd.
    And when I try to open these files, it says that it cannot, because the file is "invalid" or someting.
    I had the same problem with Photoshop Elements 5.0
    I've that problem only on that computer. Not others.
    What I can do?
    Here's a stamp: http://img510.imageshack.us/img510/7022/stamp.png
    (sorry for my really bad english)

    Well, into PhotoshopCS/Plug-in/File Formats there are those files: Cineon.8bi; Gif.8bi; Png.8bi; WBMP.8bi
    I've tried to copy all Photoshop files from another computer, where Photoshop works fine, and I've replaced with them the files on that computer, but it doesn't work yet...
    I'm thinking that's a problem of that Pc, but what?
    Thanks for all your helping, by the way.

  • Illustrator CS6 does not store the last opened files

    I need Help,
    Illustrator CS6 does not store the last opened files.

    THat indicates a permissions issue on your preferences file and/ or your files are stored on some external or network device that doesn't use persistent file paths. Look into that.
    Mylenium

  • The control chart in the sampling method does not match the insp. char. Mes

    The control chart in the sampling method does not match the insp. char.
    Message no. QD240
    how solve?????

    You need to compare 'requirement for control chart' and 'control indicator of insp. characteristic'.
    1. Requirement for control chart
    QCC0 > Quality Planning > Basic Data > Sample, SPC > Statistical Process Control > Define Control Chart Type
    See detail for your control chart and check 'requirement' in characteristic type screen area.
    2. Control indicator of insp. characteristic
    QS24
    Check 'control indicator' is suitable for requirement.
    Regards, Do Wook KIM

  • Print range does not print the last page in the range.

    Adobe Reader for New IPAD - The print range function does not print the last page in the range. For example, if you enter a print range of 2-18, pages 2-17 print and page 18 does not print.  Also, if you enter a print range of 9-9, page 8 prints and page 9 does not print.

    I have the Epson 4540 printer. I don't know for sure if it connects via AirPrint.  I didn't do any thing to set up Air Print.  The printer is attached directly to my network router and it shows up IPad apps.  I have not printed docs from other apps, but I will give it try and let you know.
    Christopher J. Bilcz
    [email protected]

  • My Sony Xperia ZL does not recognize the last update of the software

    My Sony Xperia ZL does not recognize the last update of the software or from the same mobile or from the computer app, I formatted the phone but it still does not recognize it when I give updates check it tells me that the phone have the latest software.
    Thanks

    You can find the latest available software update information on our product blog. When an update is available for your phone you will get a notification.
    If want to know more about software roll out process and how it works please see this topic.

  • SCCM 2012 does not find the last signature of SCEP

    Hi, we have installed SCCM 2012 with SCEP as our antivirus, all clients use the SCCM to download the signature, the alternate sources has been unmarked, and only we  have selected SCCM and WSUS to download the updates.
    In SCCM 2012 we have created the ADR to search and download ForeFront EndPoint Protection 2010 Security Updates. The server downloads the packages everyday at 01:00 a.m. (local time) and start to distribute to all DP at 03:00 a.m. The clients start to retrieve
    when they are switched on or from 08:00 a.m. and verify new signatures every hour from them.
    But the clients have the SCEP client update to 2 or 3 days ago! When we check the packages downloaded we note that the last package was not downloaded. This is the problem what we have. How can we solve this?
    Raulito

    Yes, I know this is an old post, but I’m trying to clean them up. Did you solve this problem, if so what was the solution?
    Have you confirmed that your ADR is running correctly?
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • DE 1.5 and 1.6 does not store the last position correctly

    Hi!
    I've seen this problem in DE 1.5, now I tried to install 1.6 and I see the problem is still here.
    I have some DRM-protected ebooks on my laptop. I open one of them, read, close on some page (for example, 162). Then I open another ebook, close it. Then I open the first ebook again and the position is 163-th page, not 162. Close and open again, the position is 164. And so on.
    I expect DE should store the last position without any "auto next page" functionality. Could somebody say me what is wrong here? Or, perhaps, this a bug of DE...

    Alexey,
    Please open a Digital Editions 1.5 Technical Support case. Use the contact links at http://www.adobe.com/support/digitaleditions.
    Regards,
    Bentley Wolfe
    Senior Support Engineer, Flash/Flash Player/Digital Editions
    Adobe

  • NACHA entry hash does not trim the last 10 digits but the first

    Our ach is ok until when entry hash total is over 11 digits the the entryhash becomes invalid as not trimming properly
    Example:
    Below is the batch_control calculation
    <POSITION>     <LENGTH>     <FORMAT>     <PAD>     <DATA>     <COMMENTS>
    <NEW RECORD>     BATCH_CONTROL
    11     10     Number     L, ‘0’     SUM(TO_NUMBER(SUBSTR
    (OutboundPayment/PayeeBankAccount/BranchNumber,1,8)))     Entry Hash
    If total entry is 10099336203
    This value should be trim with the last 10 digits 0099336203 - CORRECT
    But it is trimming from left 1009933620-WRONG
    Hiow can we fix this?

    Fixed

  • Firefox does not recognize the last java update and some videos cannot be played and some sites do not load. What to do?

    After the last update of Java, whenever checking addons, the report that is given is that the plugins "Java Deployment Toolkit 7.0550.13" and "Java(TM) Platform SE 7 U55" are outdated. Some videosites don´t load at all and some videos simply are not played. Any ideas of what goes on? (BTW, have already checked if the sites are down and no, they are not down).

    To avoid confusion:
    *http://kb.mozillazine.org/JavaScript_is_not_Java
    You can try these steps in case of issues with web pages:
    You can reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Hold down the Shift key and left-click the Reload button
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (Mac)
    Clear the cache and cookies only from websites that cause problems.
    "Clear the Cache":
    *Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox/Tools > Options > Privacy > "Use custom settings for history" > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Using IBM SVC console with firefox 4 does not display the last row of data correctly, also see same the problem with HMC console as well.

    Using Firefox 4.0.1, the IBM SVC console and the IBM HMC console both have the last line of selectable items either cut off, or overlaying the prior row of displayed items. Junked version 4 and reverted back to 3.6.17.

    Seeing the same problem using the HMC with FF7 beta.

  • Reader does not remember the last page! Disaster!

    Critical bug detected on: Nokia Lumia 620
    Adobe Reader v10.3
    Description:
    Try open any PDF file, then move pages, exit from reader, then back again in reader.
    Reader must remember last page!
    Please fix this, because it's very important feature in any reader!

    Всё ещё не пофикшено!

  • HP PSC 1300 Series printer does not print the entire last line on page

    Using an HP PSC 1310 series printer (1315xi I think). Just changed computers and OS from winXP to Win7 Professional. Now the very bottom line on my checks only shows the top 10% of that last line. There is a 1-inch margin at the bottom of 11.5" LETTER paper. There is no problem if I use another printer (HP PSC 1210xi). Is there an updated 1310 series driver that wasn't automatically selected by Win7Prof when I switched computers?

    I see no way to adjust the margins on the printer. When I click 'Printer Properties - Effects' the Margins area has nothing I can change and even though there is a box to Minimize Margins, it cannot be clicked. Using the Resizing Option to reduce page to 95% does not pull the last line into the printable area. I can print the file to PDF using doPDF v7 and then see the printable white area that goes just under the last line when I choose the 1210xi printer, but when I select the 1300 series printer the white area moves slightly upward just above most of the last line to be printed. I can't choose the pdf selection to fit or shrink to printer because that distorts the page on my pre-printed checks, so I must choose Page Scaling as 'None'. My checks printed fine on the old computer with XP and using the same PSC 1300 printer. I've also tried to print to another printer that prints the last line with no problem.

  • Copy opening does not clear the destination data - Just appends

    Hi All,
    Copy opening does not clear the destination data. It just appends so if i run the copy opening package twice i can see the signed data get doubled.
    We have SAP BPC NW 7.5 SP08 Patch 1001.
    I working on the Periodic Application.
    Copy opening Script logic:
    *FOR %TIME% = %TIME_SET%
    *RUN_PROGRAM COPYOPENING
    CATEGORY = %CATEGORY_SET%
    CURRENCY = %CURRENCY_SET%
    TID_RA = %TIME%
    OTHER = [B_ENTITY=%B_ENTITY_SET%]
    *ENDRUN_PROGRAM
    *NEXT
    Carry-forward business rules
    Source account : BALANCE SHEET ACCOUNTS
    Source flow  : F99
    Dest account :
    Dest flow  : F00
    Reverse sign : FALSE
    Data source type :  ALL
    Same period      :FALSE
    Apply to YTD : False
    Category dimension:
    ID               ACTUAL               BUDGET
    EVDESCRIPTION          Actual               BUDGET
    PARENTH1          
    YEAR               2008               2011
    COMPARISON          BUDGET               NBUDGET
    STARTMTH               1               1
    CATEGORY_FOR_OPE                    ACTUAL
    FX_SOURCE_CATEGORY          
    RATE_CATEGORY          
    RATE_YEAR          
    RATE_PERIOD          
    FX_DIFFERENCE_ONLY          
    OPENING_YEAR          
    OPENING_PERIOD          
    OWNER               [ADMIN]               [ADMIN]
    STORED_CALC          
    REVIEWER_CAT          
    Appreciate any help.
    Regards
    Mehul

    Snote 1620613 has fixed the issue
    Regards
    Mehul

  • Yesterday i made some purchases in itunestore. the download went well. till the synch of itunes with ipod. some of the downloaded music did noch synchronize. the message was: the ipod does not support the file format (mp4). strange, right?

    Yesterday 20 november I have made some purchases in Ittunestore. The download went well. Till the synch of itunes with ipod. Some of the downloaded music did noch synchronize. The message was: the ipod does not support the file format (mp4). Strange, right? All the rest of downloaded music items has been synchronised without any problems. What may be the problem?

    For music files purchased via the iTunes Store, Apple has used the following file extensions -
    .m4a unprotected AAC format music files
    .m4p protected AAC format music files
    .m4b protected Audio Books
    .m4r unprotected ringtones in AAC format
    As you can see Apple have never used .mp4 for music files via the iTunes Store.
    For videos Apple use .m4v and these are in H.264 format.
    You could try changing the file extension to .m4a, first then see if it plays on your computer and then try re-synching it.

Maybe you are looking for

  • 10.9.2 update on MacBook 5,1 (late 2008) failed

    After installing the 10.9.2 update (from 10.9.1), my Macbook 5,1 (late 2008) no longer boots. It displays some reverse video text (white on black) from a low level program (boot loader?) and stops. After a moment the graphics go funny. In 30 years, I

  • IDOC - 3rd party order

    - Assume PO to have two item with each different Sales order number. - Idoc created 3rd party SO has the PO header text, however but not the text in SO.

  • Using GOS_ATTACHMENT_LIST_POPUP - Can I send attachments to external repository?

    I've been unsuccessfully trying to use FM GOS_ATTACHMENT_LIST_POPUP to save documents in an external repository. It's only saving to the standard SAP tables: SOOD / SOFM. I've created the Business Object in SWO1. Created an entry in OAC2, and in OAC3

  • How to delete standard text in SO10

    Hi, We have lot of data in SO10 ,whcih we don't need now. How can we delete it?

  • Problems with urldecoding of %

    hi, in my servlet's post method i set request_.setCharacterEncoding("UTF-8"); and then i gonna urldecode the parameters with String value = request_.getParameter(PARAM); String decValue = URLDecoder.decode(value.trim(), "UTF-8"); everything seems to