Project

General

Profile

« Previous | Next » 

Revision 654

Added by berkley over 23 years ago

fixed error in logic. sending the filesize as an int terminated by a zero failed when the file size was greater than 256. The filesize is now sent as a string followed by a zero.

View differences:

src/edu/ucsb/nceas/metacat/DataFileServer.java
180 180
      String session_id = (new String(str,0, i-1)).trim();
181 181
      
182 182
      //get the length of the file in bytes
183
      int val2 = -1;
184
      long fsize = 0;
185
      while(val2 != 0)
183
      val = -1;
184
      i = 0;
185
      str = new byte[1024];
186
      while(val != 0)
186 187
      {
187
        val2 = in.read();
188
        if(val2 != 0)
189
        {
190
          fsize = val2;
191
        }
188
        val = in.read();
189
        str[i] = (byte)val;
190
        i++;
192 191
      }
192
      String stemp = (new String(str, 0, i-1)).trim();
193
      Long fsizetemp = new Long(stemp);
194
      long fsize = fsizetemp.longValue();
193 195
      //System.out.println("file size: " + fsize);
194 196
      
195 197
      if(!sess_id.equals(session_id))
src/edu/ucsb/nceas/metacat/DataStreamTest.java
98 98
      
99 99
      //write the length of the file followed by a 0
100 100
      long flength = file.length();
101
      //System.out.println("file sized (B): " + flength);
102
      dsout.write((int)flength);
101
      System.out.println("file sized (B): " + flength);
102
      String sflength = String.valueOf(flength);
103
      
104
      byte[] fl = sflength.getBytes();
105
      for(int i=0; i<fl.length; i++)
106
      {
107
        dsout.write(fl[i]);
108
      }
103 109
      dsout.write(0);
110
      
111
      //dsout.write((int)flength);
112
      //dsout.write(0);
104 113
      dsout.flush();
105 114
      
106 115
      // now read response from server
......
114 123
      while (cnt!=-1) 
115 124
      {
116 125
        cnt = fs.read(buf);
117
        //System.out.println("i = "+ i +" Bytes read = " + cnt);
126
        System.out.println("i = "+ i +" Bytes read = " + cnt);
118 127
        if (cnt!=-1) 
119 128
        {
120 129
          dsout.write(buf, 0, cnt);

Also available in: Unified diff