objectinputstream - Filesize excessive Java -


i have problem these 2 classes, when size of file send \ receive exceeds 1gb.the class decripter waits something, before closing stream output file, appears have been received in full (by controlling size). cripter class instead finishes without errors. since size of complete file big, can not use debugging. can not understand problem since (i think) have closed streams. class sending:

 public class cripter {        objectoutputstream out;       fileinputstream fis2;       bufferedinputstream bis;       file ifile;       public cripter(file tmpfile, objectoutputstream tmpout) {          //definizione degli stream          in = tmpin;          out = tmpout;          ifile = tmpfile;          splitfile();      }       private void splitfile() {          fileinputstream fis;           long filesize = ifile.length();          int read = 0;          long readlength = 10000000;          client.writelabelsender("criptaggio del file " + ifile.getname() + " in corso...");          byte[] bytechunk;          try {              //invio il nome completo del file              out.writeobject(ifile.getname());              //invio della dimensione completa              out.writeobject(filesize);              fis = new fileinputstream(ifile);              while (filesize > 0) {                  if (filesize <= readlength) {                      readlength = filesize;                  }                  bytechunk = new byte[(int) readlength];                  read = fis.read(bytechunk, 0, (int) readlength);                  filesize -= read;                  //lunghezza                  out.writeobject(read);                  //invio                  out.write(bytechunk, 0, bytechunk.length);                  out.flush();                  bytechunk = null;              }              fis.close();              fis = null;          } catch (ioexception e) {              e.printstacktrace();          } catch (classnotfoundexception e) {              // todo auto-generated catch block              e.printstacktrace();          }      }  } 

this class receiving:

public class decripter {     /**      * byte letti      */     int bytesread = 0;     /**      * directory in cui salvare il file completo      */     private static string directory;     /**      * nome del file completo      */     private static string filename;     /**      * stream di input      */     public objectinputstream in ;      /**      * dimensione del file completo      */     long dimensione;     /**      * file utilizzato per comporre il file finale      */     file ofile;      //stream     fileoutputstream fos;     fileinputstream fis;     fileoutputstream fostx;      /**      * costruttore che inizializza il nome e la directory del file ed effettua il riassemblamento      * @param name nome del file completo      * @param dir parte del percorso successiva filedirectory in cui salvare il file      * @param dimensione dimensione del file finale      * @param in stream di input      */     public decripter(string name, string dir, objectinputstream tempin, long tempdimensione) {         directory = dir;         filename = name; in = tempin;         dimensione = tempdimensione;         ofile = new file(directory, filename);          dereceiver();     }     /**      * metodo per la ricezione e riassemblamento del file      */     private void dereceiver() {         int check = 0;         //ricerca ed eliminazione di un eventuale duplicato del file completo         removeduplicate();         try {             //stream che accoderà byte ricevuti             fos = new fileoutputstream(ofile, true);             //blocco in cui vengono ricevuti byte             while (dimensione > check) {                 //dimensione dei bytes in ricezione                 int tempdim = (int) in .readobject();                 //preparo il buffer di byte                 byte[] mybytearray = new byte[tempdim];                 //ricevo byte                 in .readfully(mybytearray);                 //traccio byte che ho letto                 check += tempdim;                 //scrivo su file                 fos.write(mybytearray);                   //svuoto lo stream                 fos.flush();                 //resetto il buffer                 mybytearray = null;             }             //chiudo lo stream             fos.close();             fos = null;         } catch (ioexception e) {             e.printstacktrace();         } catch (classnotfoundexception e) {             e.printstacktrace();         }     }     /**      * metodo per la rimozione del file completo già presente nella directory      */     public static void removeduplicate() {         file direc = new file(directory);         (file temp: direc.listfiles()) {             if (temp.getname().equals(filename))                 temp.delete();         }     } } 

thanks in advance , sorry errors of post.

if i've read code correctly, problem sender format doesn't match receiver format.

when send this:

  1. send file-name
  2. send file-size
  3. send chunk-size
  4. send chunk-size bytes
  5. go 3

when receive this:

  1. send chunk-size
  2. send chunk-size bytes
  3. go 1

if isn't problem, please provide sscce ... can examine code running.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -