Can't fully download long web-pages using HttpURLConnection

I'm using these two methods:
/**keeps document encoding or sets Cp1251 as default
      * @param uri is uri to document
      * @return {@link InputStreamReader} with encoding
     public static InputStreamReader getInputStreamReader(String uri) throws IOException{
          URL url = new URL(uri);
          HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
          urlConn.setConnectTimeout(timeout);
          urlConn.setDefaultUseCaches( false );
        urlConn.setUseCaches( false );
        urlConn.setRequestProperty( "Cache-Control", "max-age=0,no-cache" );
        urlConn.setRequestProperty( "Pragma", "no-cache" );
        String encoding = urlConn.getContentEncoding();
        if(encoding == null || encoding.equals("") ){
             String Content_Type = urlConn.getHeaderField("Content-Type");
             if(Content_Type.contains("charset=")){
                 String[] t = Content_Type.split("charset=");
                 if(t != null && t.length>0){
                      encoding = t[t.length-1];
        if(encoding == null || encoding.equals("")){
             encoding = "windows-1251";
        InputStreamReader isr = new InputStreamReader(urlConn.getInputStream(), encoding);
        return isr;
     /**Returns content in default charset
      * @param uri is uri to document you want to get
      * @return String with encoding equal to {@link Charset.defaultCharset()}
     public static String fetchEncodedURI(String uri) throws IOException{
          InputStreamReader isr = getInputStreamReader(uri);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          OutputStreamWriter osw = new OutputStreamWriter( baos, Charset.defaultCharset());
          char[] buffer = new char[256];
          int n = -1;
          while ( (n = isr.read(buffer))!= -1 ){
               osw.write(buffer, 0, n);
        String outputString = new String(baos.toByteArray());
        osw.flush();
        osw.close();
        baos.flush();
        baos.close();
        return outputString;
     }The problem is that some pages are cut! I make output of result string (outputString) ans see for example just 2/3 of the real page content.
Is it possible to overcome this difficulty?
Edited by: Holod on 01.10.2008 11:31

ejp wrote:
Personally, I'd suggest reading the whole page as bytes into baos and covert to string with one call to boas.toString(encoding)Or use a StringWriter. The way you're doing it is the worst of both worlds.Can you help me please with a sample link?
Or please tell, is it right solution?
         /**Returns content in default charset
      * @param uri is uri to document you want to get
      * @return String with encoding equal to {@link Charset.defaultCharset()}
     public static String fetchEncodedURI(String uri) throws IOException{
          InputStreamReader isr = getInputStreamReader(uri);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          //OutputStreamWriter osw = new OutputStreamWriter( baos, Charset.defaultCharset());
          StringWriter sw = new StringWriter();
          char[] buffer = new char[256];
          int n = -1;
          int previousPosititon = 0;
          while ( (n = isr.read(buffer))!= -1 ){
               sw.write(buffer,previousPosititon,n);
               previousPosititon+=n;
               //osw.write(buffer, 0, n);
        //osw.flush();
     //String outputString = new String(baos.toByteArray());
        String outputString = sw.toString();
        //osw.close();
        baos.flush();
        baos.close();
        return outputString;
     }Edited by: Holod on 03.10.2008 5:41

Similar Messages

  • Can we download a web page using SOA?

    Hi,
    We have a requirement to download a web page whether html or xml format by using SOA middleware.Is it possible with this? Have anyone tried with this earlier? Any suggestions regarding this will be of great help.
    Thanks,
    SOA Team

    Hello Iyanu_IO,
    Thank you for answering my question "can I download a web page as a PDF".
    I downloaded and installed the add-on and it works really well.
    Regards
    Paul_Abrahams

  • Why can't I successfully upload web pages using FTP?

    I recently installed Adobe Dreamweaver and successfully connected to a remote server where the files on my existing website are stored. I was then able to call up web pages from my local site, make revisions and successfully upload them (using FTP) to the remote server.
    Problem started occurring when I received a Dreamweaver prompt advising me to change the name of my website's root folder from Unnamed Web Folder 1 to the actual location of the files on my i-Mac hard drive. In doing so, I moved the path of the site and changed the name of the root fokder.
    Since then, when I make revisions on a locally stored web page and try to upload it to my remote server (by clicking on the "put" upward arrow), the operation seems to be excuted correctly. But when I test the revised page on a separate browser (like Safari or MI Explorer), the un-revised web page is displayed.
    In trying to remedy the situation. I fear that I've been digging a deeper and deeper hole and may have screwed things up even further.
    Help!

    I'm really confused.  So let's back up about 4 steps.
    Local site files should be on your hard drive.  The same computer hard drive that Dreamweaver is installed on.  For sake of argument, let's put your site files into a folder called YourSiteName on your C: drive.  Do not use any spaces or special characters in your folder or filenames.
    LocalSite = C:\YourSiteName
    Then tell DW where to find that folder as in the screenshot I posted earlier.
    Next, define your remote server settings and tell DW which root directory your hosting company told you to use for your site files.  Some hosts use public_html or htdocs or www.  And some hosts don't use one at all in which case you leave that field blank.
    See screenshots.
    Next hit More Options.
    Hit the test button to confirm you can connect to the remote server.
    Nancy O.

  • Can't convert certain IE Web Pages using Acrobat 9 Pro

    http://mediasolveconnect.com/demo/?scene=test1#Endcap-Sponsorship
    I am able to successfully convert various web pages in IE to pdf however when I try to convert the pages on this site I only get a solid black page.

    This page is a Flash site, while Acrobat supports importing Flash content, entire sites built in Flash often have issues displayed as a PDF page.

  • How can I capture long web pages using RoboScreen Capture?

    Hi,
    I want to capture long webpages or scrolling windows using RoboScreen Capture. There is no such mode availble in the menu.
    Help would be appreciated.
    Thanks,
    Deepti

    Hi,
    Thank you for the welcome.
    Please have a look at this post
    http://help.adobe.com/en_US/FrameMaker/8.0/help.html?content=Chap-23-TechCommSuite_2.html
                                                          OR
    http://help.adobe.com/en_US/framemaker/using/WS4279000F-ACA5-403b-B46F-BD80A744B03B.html
    Under "You can use RoboScreen Capture to perform the following tasks: ", check out the fourth bulleted point .
    I am using RoboHelp 8 and RoboScreen Capture is part of it.
    Regards,
    Deepti

  • Why can't i print a web page,

    why can't i print a web page, using windows vista 64, HP photosmart 8250?

    This software can help print from the web:
    http://h10025.www1.hp.com/ewfrf/wc/document?docnam​e=c01812475&cc=us&dlc=en&lc=en&product=443024&tmp_​...
    This utility can help determine if things may not be setup correctly:
    http://h10025.www1.hp.com/ewfrf/wc/softwareDownloa​dIndex?cc=us&lc=en&jumpid=ex_r4155/hho/ipg/ccdoc/p​...
    007OHMSS
    I was a support engineer for HP.
    If the advice resolved the situation, please mark it as a solution. Thank you.

  • I recently downloaded a web page but then i deleted history which deleted the web page. there is still a short cut to it but says file does not exist. can i retrieve this as web page no longer exixts

    as the question states i downloaded a web page but before i put it on a memory stick i changed the options on my firefox and the file is no longer there.
    there is a shortcut in the 'recently changed' folder in windows explorer but when i click on it it says the file has moved or no longer exists.
    Is there anyway to retrieve this as the web page no longer exists

    Try:
    *Extended Copy Menu (fix version): https://addons.mozilla.org/firefox/addon/extended-copy-menu-fix-vers/

  • How can I add a podcast episode to an existing web page using iWeb?

    How can I add an episode to an existing web page using iWeb?
    I could probably figure this out but I am afraid if I make changes to the site and re-upload it to the podcast area I will have just doubled it. I see them repeated from time to time.
    What is the proper protocal? Thanks
    Mac G4   Mac OS X (10.4.3)  

    Hi apple-owner,
    Method 1.
    To create this scatter-plot, I selected the whole of Columns A and B. (Shift click on the Column reference tabs).
    The plot ignores blank rows, but they are "ready" for new data:
    Method 2
    If you did not select whole columns, you can extend the "active" rows. Rows 1-5 selected:
    Add more data rows and drag the fill handle (small white circle, bottom right) down
    Regards,
    Ian.

  • Why the speed of MacBook Air to download a web page is lower than iPad2? Even worse sometimes Ipad2 can but MBA can't load the web pages.

    Why the speed of MacBook Air to download a web page is lower than iPad2?
    Even worse ,Why sometimes iPad2 can but MBA can't load the web pages?

    Why the speed of MacBook Air to download a web page is lower than iPad2?
    Even worse ,Why sometimes iPad2 can but MBA can't load the web pages?

  • Download a web page, how to ?

    Can any one help me with code for downloading a web page given the url address ? I can download the page, but the problem is it doesn't download the associated images, javascripts etc. neither does it create an associated folder as one might expect when saving a page using browser.
    Below is the code snippet -
                        URL url = new URL(address);
                        out = new BufferedOutputStream(
                             new FileOutputStream(localFileName));
                        conn = url.openConnection();
                        in = conn.getInputStream();
                        byte[] buffer = new byte[1024];
                        int numRead;
                        long numWritten = 0;
                        while ((numRead = in.read(buffer)) != -1) {
                             out.write(buffer, 0, numRead);
                             numWritten += numRead;
                        System.out.println(localFileName + "\t" + numWritten);

    javaflex wrote:
    I don't think web crawler would work
    webcrawler simply takes every link or url on the given address and digs into it ..
    Would it work for javascripts ? Given a url like xyz.com/a.html,
    1. the code above would downlod the plain html.
    2. parse html to find javascripts, images (anything else I need to look at ?)
    3. download those
    4. put everything in one folder (but the question is then do I need to rename the pointers in the dwnlded html to point at the other contents on the disk ? )
    This is naive approach - anything better ?
    thanks.More advanced web-crawlers parse the JavaScipt source files (or embedded JS sources inside HTML files) and (try) to execute the script in order to find new links. So the answer is: yes, some crawlers do. I know for a fact that Heritrix can do this quite well, but it is a rather "large" crawler and can take a while to get to work with. But it really is one of the best (if bot the best) open source Java web-crawlers around.

  • Redirect to "can't find the i-web page"/file name change

    i published a website thru mobileme (http://www.hale-o-lani-aloha.com). when i type my website address in e-mails and check the link, i sometimes got directed to a page that said "we're sorry but we can't find the i-web page you've requested..." (yes, i've checked my typing!)
    when i created my sitemap (with rage sitemap automator), i was told that the apostrophe in the file name for my first page was probably causing the problem. my file name was"hale o'lani aloha". i changed the file name for the webpage to "hale o lani aloha" and republished, redid the sitemap, etc. i now have 2 sets of files on my i-disk: one for Haleo'LaniAloha and the other for HaleoLaniAloha (i don't know why it's not "HaleoLani"). both sets of files have folders with the individual components of the site, css style sheet, java script and html files. the bad redirect site address has "/Site/HaleoLaniAloha" in the address. (when i checked the "oLani" html file on my i-disk, it opens an incomplete version of my first webpage. however, the "o'Lani" html file opens the fully functioning page). when the links work, the address has "/Site/Haleo_LaniAloha" (the new file name). so that long explanation brings me to my questions:
    - did the apostrophe in my file name truly mess things up?
    - since my fully functioning html file on i-disk has the apostrophe in it, should i rename my file with the apostrophe and delete the non-apostrophe files from my i-disk (even tho the working website has "oLani")?
    thanks for any info that can help clear up this mess!

    You can find import now in the Library:
    *Bookmarks > Show All Bookmarks > Import & Backup > Import Data from Another Browser

  • I want to make a web page using labview.

    I want to make a web page using labview. I have the internet tool kit. Where do I start. Till now all I have used labview is for industrial I/O and mmi. I have used various TCP UDP comms for network purposes, but I haven't ever done anything with Web page design.

    The internet toolkit has some functions for generating and manipulating HTML, but it isn't really intended as a Web page authoring tool. I personally wouldn't use it for such a purpose, and I've done a good bit of Web programming in various different environments, including LabVIEW.
    The true power of the internet toolkit lies in its ability to create LabVIEW VIs to handle CGI requests, the way that perl or PHP might be used in more traditional Web development. In the old days, this was really the only way to provide Web interactivity with LabVIEW on the back end. Here is a document that outlines how to start up the toolkit's Web server and check out the CGI examples that ship with LabVIEW. This is the best jumping-off point for creating your own pages, if you are planning to use the CGI functionality in the internet toolkit. Just examine how the HTML pages and the CGI VIs in the examples work together and begin to try out your own VIs.
    Since LabVIEW 6i, LabVIEW has shipped with Remote Panel functionality that allows you to publish any LabVIEW VI in a Web browser without the burden of creating special CGI functionality. Furthermore, users can fully interact with the VI--buttons, graphs, string controls, etc. That's really a better solution if you want to make VIs available via the Web and aren't so much interested in CGI/transactional behavior. Check this out by choosing Tools >> Web Publishing Tool from LabVIEW.
    I hope this info gives you some ideas about starting points for Web functionality in LabVIEW. Please follow up if you have more specific questions.
    Best Regards,
    John

  • Where to Download WPC [ Web Page Composer ] and How to install it ?

    Hi Experts,
    I need to download the Web Page Composer and install for our use in my company. Can anyone help me
    on this where to get it and and how to install ?
    thanks
    Suresh

    Hi,
    Chech the SAP Note Number: [1080110 |https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_ep_km/~form/handler]
    Also some links that may help you:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d07b5354-c058-2a10-a98d-a23f775808a6
    There are also lots of documents available on SDN, so just use SDN search.
    Regards,
    Praveen Gudapati

  • Can't fully download Photoshop

    Can't fully download Photoshop

    Download the trial version from http://prodesigntools.com/adobe-cs6-direct-download-links.html and use your serial number to activate it.
    Note that you need to follow the Very Important Instructions on that page before proceeding to the actual download.

  • Silent print a PDF from a web page using Flex. We are targeting Windows and Mac with Arcobat reader installed

    We are planning to Silent print a PDF from a web page using Flex. We are targeting Windows and Mac with Arcobat reader installed. I have tried using the AIR appliaction and it worked, But our requirement is NO INSTALL to the user machine for the silent printing. It is just from web page and silent printing to the default printer to the desktop/Laptop. Can anyone share your thoughts and experience with us. It will be very helpful..
    For AIR : I tried the thread Re: AIR and PDF showing/silent printing

    Hey CodeMonkey & Ross,
    Did you either of you ever find a solution? I'm stuck too, it seems I can get remote printing on all these PDFs to work but it just prints a blank page since I've been using Javascript in the browser, not Adobe's (they are Engineering drawings that I do not have permission to edit so I can't just insert code into them but I need to make work instructions). I've been scouring the internet for hours now, it seems that this thread is the only relevant/useful one at this point. No one else was trying to achieve this for similar reasons to mine.
    Thanks guys,
    Lox

Maybe you are looking for

  • How do you save css rules created in web inspector?

    Being a web developer, I usually use Firebug on Firefox to test CSS when I'm developing a website. Ever since I got my new iMac, I've really grown to love Safari. I like the Web Inspector but I cannot seem to find a way to copy any of the CSS rules I

  • Can't sync my Macbook with my new Nokia Lumia 900.

    I spent two hours with a couple of the tech folks at the AT&T store yesterday, trying to get my new Nokia Lumia 900 to sync to my Macbook... but with no luck. No matter what we did, I kept getting a message that the server was not secure, and so the

  • I updated  my Iphone 4 to IOS 7.1.2 and i loss all my Pictures

    Hi When I did update to my iPhone (IOS 7.1.2) the phone automatically turn off and then ask my to connect with iTunes I don't know why ? that is a first time always just do the update from phone, I connect the iPhone with iTunes and ask me to do back

  • Is there a way to set pixels at 20ppi?

    I'm using AI to produce tactile graphics [for the blind] on a 20dpi dot-matrix embosser. With so few available dots, aligning elements with the pixels is essential for consistent lines. I know how to set up a new doc for pixels, align with pixels, pr

  • Can't run a workflow manually. I got this error: 'StartWorkflowOnListItem' does not have an implementation.

    Hello Everybody, I have a site collection in sharepoint 2013. When I go to site contents and then click on workflows I got this error: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider' fro