Get the upload size?

I have just read this topic
http://forum.java.sun.com/thread.jspa?threadID=451245&start=0&tstart=0
how can i get how meny bytes i have already send in the program?
The size() method is just return the size read in to the memory.......
     public void writeFile(String name, String mimeType, String fileName, InputStream is) throws java.io.IOException {
          if(is == null) {
               throw new IllegalArgumentException("Input stream cannot be null.");
          if(fileName == null || fileName.length() == 0) {
               throw new IllegalArgumentException("File name cannot be null or empty.");
          out.writeBytes(PREFIX);
          out.writeBytes(boundary);
          out.writeBytes(NEWLINE);
          out.writeBytes("Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + fileName + "\"");
          out.writeBytes(NEWLINE);
          if(mimeType != null) {
               out.writeBytes("Content-Type: " + mimeType);
               out.writeBytes(NEWLINE);
          out.writeBytes(NEWLINE);
          byte[] data = new byte[1024];
          int r = 0;
                while((r = is.read(data, 0, data.length)) != -1) {
               out.write(data, 0, r);
                        System.out.println(out.size());//I can't understand why?
          try {
               is.close();
          } catch(Exception e) {System.out.println(e);}
          out.writeBytes(NEWLINE);
                System.out.println(out.size());
          out.flush();
     }

sorry for my poor English >_<"
http://img1.IMGSatellite.com/u/05/142/13/project.rar
You can download the program to try about upload......
I want upload a 700kb file,and my upload speed is 50 kb/s
so....I have to spend 14sec at least.....
but the sum of the 'r' shows
1024
2048
744448
745472
746496
747520
748544
749568
750592
751616
752640
753664
754688
755712
756736
757760
758784
759808
760832
761856
762880
763904
764854
sum of the 'r' jump to 764854 not more then 1sec....
In normal, The bytes I have already send should be about 51200 in first sec
I want to know the bytes I have already send but the sum of the 'r' only shows The bytes of file.

Similar Messages

  • Help ...how to get the file size on a server

    Hi.I use this code to parse a file that is on a server.
    The question is: how can i get the file size (bytes size)?
    Thanks.
    //Open the file for reading:
    URL u = new URL(entry);
    InputStream inputXML = u.openStream();
    //Build document:
    DocumentBuilder builder = factory.newDocumentBuilder();
    doc = builder.parse(inputXML);

    Try this instead:
    URL u = new URL(entry);
    URLConnection conn = u.openConnection();
    // get the file size
    int size = conn.getContentLength();
    // open the input stream from the URLConnection (which is functionally the same as opening it directly from the URL)
    InputStream inputXML = conn.getInputStream();
    Shaun

  • How do I get the byte size of a server file before sending output via HTTP?

    I need to get the byte size of the file prior to streaming it. I can't seem to find a class/method I need. Basically, I have the path c:\\tomcat\\webapps\\documents\\sample.pdf in the servlet, I was hoping I could just use something from the File class but I couldn't find anything that seems to do the trick?
    thanks, in advance,
    Chuck

    maybe the source of the problem will help...I am trying to stream a PDF to IE and a blank page is being generated although all other file type work.
    I have found a lot of answers in the forum but no specific code examples. Here's what I have so far from picking through threads in here (can someone please show me how to get the byte size of the file so that I can assign it to the method response.setContentLength();?):
    String CONTENT_TYPE = " ";
         String target = " ";
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
         StringBuffer buf = new StringBuffer();
         HttpSession session = request.getSession();
         String file = request.getParameter("filename");
         target = file;
         int end = file.length();
    int beg = end-2;
         String type = file.substring(beg, end);
         if (type.equals("DOC")){
              CONTENT_TYPE = "application//vnd.msword";
         }else if (type.equals("XLS")){
              CONTENT_TYPE = "application//vnd.x-excel";
         }else if (type.equals("PPT")){
              CONTENT_TYPE = "application//vnd.ms-powerpoint";
         }else if (type.equals("PDF")){
              CONTENT_TYPE = "application//vnd.x-pdf";
         }else if (type.equals("MPP")){
              CONTENT_TYPE = "application//vnd.ms-project";
         }else if (type.equals("ZIP")){
              CONTENT_TYPE = "application//ZIP";
         }else if (type.equals("TXT")){
              CONTENT_TYPE = "text//plain";
         }else {
              CONTENT_TYPE = "text//html";
         //File f = new File(file);
         //int l = f.length();
         response.setContentLength(l); <----- supposedly this fixes my problem but I don't know how to get the byte szie of the file in an integer??
         // reset the response
         response.reset();
         response.setContentType(CONTENT_TYPE);
         try{
         // Get streams
         FileInputStream fileInputStream = new FileInputStream(target);
         ServletOutputStream servletOutputStream = response.getOutputStream();
         // Init byte count and array
         int bytesRead = 0;
         byte byteArray[] = new byte[4096];
         // Read in bytes through file stream, and write out through servlet stream
         while((bytesRead = fileInputStream.read(byteArray)) != -1) {
         servletOutputStream.write(byteArray, 0, bytesRead);
              servletOutputStream.flush();
         // Flush and close streams
         servletOutputStream.flush();
         servletOutputStream.close();
         fileInputStream.close();
         } catch (Exception e) {
         System.out.println(e.toString());

  • I am trying to make a pdf of a file and I need to get the file size to be no bigger than 10MB. What is the best way to do this

    I am trying to make a pdf of a file and I need to get the file size to be no bigger than 10MB. Even when I save it, the image quality at minimum the file size is 10.9 MB. What is the best way to do this

    @Barbara – What purpose is that PDF for? Print? Web?
    If web purpose, you could convert CMYK images to sRGB. That would reduce the file size as well.
    A final resort to bring down file size is:
    1. Print to PostScript
    2. Distill to PDF
    That would bring file size down even more. About 20%, depending on the images and other contents you are using, compared with the Acrobat Pro method. If you like you could send me a personal message, so we could exchange mail addresses. I could test for you. Just provide the highres PDF without any downsampling and transparency intact. Best provide a PDF/X-4.
    I will place the PDF in InDesign, print to PostScript, distill to PDF.
    Uwe

  • Getting the page size in PDF file

    i want know how do get the page size in PDF file befor placing every page in document
    for example height=297 mm And width=210mm

    This script:
    http://indesignsecrets.com/zanelli-releases-multipageimporter-for-importing-both -pdf-and-indd-files.php
    answers all your questions.
    Peter

  • I cannot upload any pictures to Flickr for the past three days, I just get the upload screen which when I click on upload does nothing I'm using PSE12

    I cannot upload any pictures to Flickr for the past three days, I just get the upload screen which when I click on upload does nothing I'm using PSE12, I have had no problems in the past , I still have had no response to this post and it has been several weeks since initially posted, is there anyone awake at Adobe, can someone give me advice or is there total lack of interest once the product has been purchased I have been a customer of PSE for many year since PSE6 now on 12 but lack of response may cause me to rethink

    Turn off your iPad and put it in recovery mode. Try to restore it via iTunes.
    http://support.apple.com/kb/HT1808

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Getting the page size and knowing how many pages they are in PDF file

    Hi There,
    when i do this script (
    var myPDFFile = File.openDialog(["Choose a PDF File"]); ) 
    with JS via Windows it is used for opening a new PDF file when i import this file i need to
    get the page size and how many pages they are in PDF file. but i dont know how to do it.
    please help me.

    Ask here: http://forums.adobe.com/community/indesign/indesign_scripting

  • How to get the disk size

    Hi, everyone, does anyone know how to get the size of the disk, say hard disk? In the Writing Device Driver it says that the block device driver must create an 'nblocks' property for each minor block device. I want to get the size of the block device in another driver. Is there any DDI/DKI kernel function for this?
    How to get the same thing in a user mode application? Is there any API to do this?
    Thank you very much.

    I just found a function in include/sys/conf.h. The prototype is:
    extern int bdev_size(dev_t);
    Can I use this function to get the disk size of the device dev_t? I couldn't find the documentation of this function.
    Thanks

  • How to get the correct size of the loaded swf file?

    final public class main extends Sprite
      public function main()
       loaderInfo.addEventListener(Event.COMPLETE, _onLoadCompleted);
      private function _onLoadCompleted(event: Event): void
       var tw: int = stage.width;
       var th: int = stage.height;
       var tsw: int = stage.stageWidth;
       var tsh: int = stage.stageHeight;   
    Above is my simple as3 project in flex builder 3.
    My screen resolution is 1920*1080, when debugging, the swf is stretched to the full client area of the IE, but the stage.stageWidth is 500 and the stage.stageHeight is 375, both the stage.widht and stage.height are 0, who can tell me why and how to get the right size of the swf file, named the client area size of the IE in this situation?
    Thanks very much!

    The HTML wrapper might resize the SWF later, so wait a frame and check stageWidth/stageHeight again.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Get the file size of a file on the server.

    okay.. for my download manager i need to get the file size. I tried using the available method of inputstream, and the getContentLength() of URLConnection, which worked but only for webpages. so does anyone know how to do this? Sun does it in SDM, but i dont think the source is included. ill download it again and check.
    thanks.

    content-length is not guaranteed to be anythingi dont think so. correct me if i am wrong..
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#s
    c4.4 states -
    " When a Content-Length is given in a message where a
    message-body is allowed, its field value MUST exactly
    match the number of OCTETs in the message-body.
    HTTP/1.1 user agents MUST notify the user when an
    invalid length is received and detected."
    this sort of guarantees that if a file is being
    downloaded the content-length gives the size of the
    file. i am able to confirm this by sniffing the
    traffic of my download manager.This is only guaranteed if the content length field is present. :-)
    However, looking two paragraphs up:
    'All HTTP/1.1 applications that receive entities MUST accept the "chunked" transfer-coding (section 3.6), thus allowing this mechanism to be used for messages when the message length cannot be determined in advance.'
    There is mechanism built in for cases where the size cannot be determined.
    Regards,
    Bhaveet

  • Dual library question (iTunes gets the library size and bitrate wrong)

    I have two libraries, one ripped in Lossless, and the other in AAC at 256 kbps. I use one for streaming, and the other for syncing to our iPods. I just switched from the Lossless library to the AAC library (kept on separate drives). iTunes now sees the AAC files, but incorrectly lists all the bitrates as their higher Lossless numbers. However, when I click on an individual song to play it, the bitrate appropriately is recognized as 256 kbps. When I do this, the total library size (listed at the bottom) also incrementally "shrinks."
    The problem is that I just purchased a new 80 GB iPod capable of holding the entire library (nearly 8000 songs@25 kbps, ~60 GB total size). Unfortunately, iTunes still thinks the library is much larger (using the incorrect lossless bitrates to calculate file size). This results in it telling me (erroneously) that the library is too large to sync.
    Is there an easy way to get iTunes to realize the new file sizes? I could obviously double-click on each and every song in the library until iTunes "gets" the real size, but I assume there's a better way. I also assume that this will be an issue every time I switch between the two libraries.
    Help, anyone? Thanks in advance.
    KK
    iMac G5, Mini, PB G4   Mac OS X (10.4.6)  

    Thanks for the tip, but this didn't work, unfortunately. Following your lead a bit further, I even created a new playlist and dragged the whole library there, but the wrong bitrates (and thus, playlist size) still appeared.
    One more curious update regarding this situation. iTunes automatically populated my iPod with what it believed was a subset of my tunes that would fit on the iPod. The real size of this subset was ~20GB, but iTunes thought (using the Lossless size) that it was nearly 60 GB. In categorizing the contents of my iPod, it listed ~60GB of songs, ~1 MB of photos, 1 GB of video and still listed the space available as ~50 GB (for a grand total of ~112 GB of space on my 80 GB iPod). Clearly, iTunes used the calculated size to estimate the music content, but used the actual space remaining based on a query of the iPod drive. Strange, huh?
    I'm still looking for advice--any other suggestions would be welcome.
    KK

  • In iPhoto most of my photos appear to have been replaced by much smaller versions. What has happened and how can I get the full size photos back?

    In iPhoto most of my photos appear to have been replaced by much smaller versions. What has happened and how can I get the full size photos back?

    That is either a bug in Firefox 5 or the script has a problem with Firefox 5.<br />
    It works in all other Firefox versions like Firefox 3 and 4 and 6 (Aurora) and 7 (Nightly).

  • My photo stream does not seem to be working as before with the new PHOTOS update. some of my devices are not getting the uploads/downloads

    My photo stream does not seem to be working as before with the new PHOTOS update. Some of my devices are not getting the uploads/downloads, anyone have this problem?

    Recommend that you post your question in "Photos".
    Remember, Photos is not a replacement for Aperture.

  • Getting the actual size of the result of a query

    Hi,
    I would like to ask if someone knows on how to get an estimate size of the result of a query on a table. To make it more specific, here is an example.
    Let us say I have this table called EMP and it has a column called DATE. I have issued a query like this:
    select * from EMP where DATE < to_date('01-AUG-08');
    I want to get the actual size of the result of the query in bytes or MB. How would i achieve this without creating another table and transferring the data on it.

    You can use SQL*Plus Autotrace to have the data size sent between client and database session:
    SQL> set autotrace traceonly statistics;
    SQL> select * from employees where hire_date < to_date('01/08/08');
    107 rows selected.
    Statistics
            430  recursive calls
              0  db block gets
            123  consistent gets
             11  physical reads
              0  redo size
           9405  bytes sent via SQL*Net to client
            457  bytes received via SQL*Net from client
              9  SQL*Net roundtrips to/from client
              3  sorts (memory)
              0  sorts (disk)
            107  rows processed
    SQL>Edited by: P. Forstmann on 25 janv. 2011 18:55

Maybe you are looking for

  • Sub-set of Universal Worklist as a Item Specific Worklist

    Hi We are developing a bespoke system which will use SAP workflow to populate the UWL with tasks and notifications.  The tasks will refer to a specific item ie a single proposal and a user will receive tasks on more than one proposal. The user will b

  • How to populate a field on the Self Registration Approval Form?

    Hello, I have a field named SSN (last 4 digits of the SSN) that a self registered user must fill in during self registration. After the user submits the request, the request is submitted to a reviewer. This reviewer logs in and accesses the Self Regi

  • Core files for GLLEZL in  /var/core

    Hi All, We are running on 11.5.10.2 and in 10.2.0.3 DB Today we got lots of core files in /var/core directory core_<server name >GLLEZL201_201_1257203633_25107 Can you please advice on why these were generating and any issues are there because of thi

  • Problem in starting Integration Repository

    Contrary to another thread that I found, I am having problems starting Integration Repository for the first time after installation. I followed the instructions of the installation guide up to the point of running SXMB_IFR to launch SAP Exchange Infr

  • Spry Panels and FireFox issue

    I can't get my spry panels to position correctly in Firefox but are fine in the other browsers. Can someone please advise?? Thanks! Janie http://0000uhy.previewcoxhosting.com/Pages/ourservices.html