java - getting Connection reset by peer exception (toplink) -


i using following code ensure file contents written disk

public void copyfilefromurl(url source, file target, int count) throws ioexception {      inputstream in = null;     outputstream out = null;          if (target != null) {         try {             if (!target.exists()) {                 target.createnewfile();                 if (source == null) {                     return;                  } else {                         in = source.openstream();                    }                 out = new fileoutputstream(target);                 byte[] buf = new byte[1024];                 int len;                 while ((len = in.read(buf)) > 0) {                     out.write(buf, 0, len);                 }                                log.debug("the contents url: " + source + " written file " + target);                               //add successfull             } else {                 log.debug("skipping creation of asset");             }         } catch (exception e) {               if(count < 3){                    if (in != null) {                        in.close();                  }                 if (out != null) {                        out.close();                    }                  // attempt delete                 boolean success = target.delete();                   if (!success) {                      log.debug("unable delete " + target);                     } else {                         copyfilefromurl(source, target, ++count);                    }                 } else {                     log.debug(e.getclass().getname());                 e.printstacktrace();                         }             } {              if (in != null) {                    in.close();              }             if (out != null) {                    out.close();                }              }     } } 

i calling code this

while(iter.hasnext()) {     coursematerials cm = iter.next();            string url;     try {         asset asset = cm.getasset();         list<assetversion> av = asset.getassetversions();      } catch (exception e1) {         log.debug("bad asset skipping...");         e1.printstacktrace();         continue;     }      ....      try {         url earl = new url(visualelementurl);         scormfilewriter.copyfilefromurl(earl, new file(absolutefilename), 0);     } catch (exception e) {         e.printstacktrace();         return false;     } } 

now how trying like, when come function copyfilefromurl(), unplug cable, tries 2 times, on third time plug in cable. function returns successfully. in while loop. after when come line

asset asset = cm.getasset(); 

i connection reset peer exception. skips asset , again starts normally. why ? why getting connection reset peer exception ? if getting exception because of unplug cable should other assets also, getting exception next iteration, starts working fine, mean line asset asset = cm.getasset(); throws no exception after throwing first time?

why happening? how can overcome it?

i using sql server 2008 database.

thanks

you may try using flush() method before close() method


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -