Changeset 846


Ignore:
Timestamp:
02/05/14 16:08:38 (10 years ago)
Author:
jts21
Message:

Different receieve method that doesn't seem to corrupt images anymore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/network/ImageSaver.java

    r843 r846  
    2727        FileOutputStream out = new FileOutputStream(file);
    2828        // file is the remaining bytes of the stream
    29         byte[] buf = null;
    30         if(fileLen > 1024) {
    31                 buf = new byte[1024];
    32                 while(fileLen > 1024) {
    33                         is.read(buf);
    34                         out.write(buf);
    35                         fileLen -= 1024;
     29        byte[] buf = new byte[1024];
     30        int r = -1;
     31        int len = 0;
     32        while((r = is.read(buf)) > 0) {
     33                out.write(buf, 0, r);
     34                len += r;
     35                if(fileLen - len <= 0) {
     36                        break;
     37                }
     38                if(fileLen - len < 1024) {
     39                        buf = new byte[fileLen - len];
    3640                }
    3741        }
    38         buf = new byte[fileLen];
    39         is.read(buf);
    40                 out.write(buf);
    4142                out.flush();
    4243        out.close();
Note: See TracChangeset for help on using the changeset viewer.