📄 dataconnection.java
字号:
con.fireProgressUpdate(file, FAILED, -1); return; } len += read; if(read == -1) { break; } fOut.write(buf, 0, read); con.fireProgressUpdate(file, type, len); if(time()) { // Log.debugSize(len, true, false, file); } if(read == StreamTokenizer.TT_EOF) { break; } } fOut.close(); //Log.debugSize(len, true, true, file); } else { // no resuming while(true) { //System.out.println("."); int read; try { read = in.read(buf); } catch(IOException es) { Log.out("got a IOException"); ok = false; bOut.close(); con.fireProgressUpdate(file, FAILED, -1); return; } len += read; if(read == -1) { break; } bOut.write(buf, 0, read); con.fireProgressUpdate(file, type, len); if(time()) { //Log.debugSize(len, true, false, file); } if(read == StreamTokenizer.TT_EOF) { break; } } bOut.flush(); bOut.close(); //Log.debugSize(len, true, true, file); } } catch(IOException ex) { ok = false; debug("Old connection removed"); con.fireProgressUpdate(file, FAILED, -1); //debug(ex + ": " + ex.getMessage()); ex.printStackTrace(); } } } } if(type.equals(PUT) || type.equals(PUTDIR)) { RandomAccessFile fIn = null; if(in == null) { try { fIn = new RandomAccessFile(file, "r"); if(resume) { fIn.skipBytes(skiplen); } //fIn = new BufferedInputStream(new FileInputStream(file)); } catch(Exception ex) { debug("Can't open inputfile: " + " (" + ex + ")"); ok = false; } } if(ok) { try { out = new BufferedOutputStream(sock.getOutputStream()); } catch(Exception ex) { ok = false; debug("Can't get OutputStream"); } if(ok) { try { int len = skiplen; char b; while(true) { int read; if(in != null) { read = in.read(buf); } else { read = fIn.read(buf); } len += read; //System.out.println(file + " " + type+ " " + len + " " + read); if(read == -1) { break; } out.write(buf, 0, read); con.fireProgressUpdate(file, type, len); if(time()) { // Log.debugSize(len, false, false, file); } if(read == StreamTokenizer.TT_EOF) { break; } } out.flush(); if(in != null) { in.close(); } else { fIn.close(); } //Log.debugSize(len, false, true, file); } catch(IOException ex) { ok = false; debug("Error: Data connection closed."); con.fireProgressUpdate(file, FAILED, -1); ex.printStackTrace(); } } } } } } catch(IOException ex) { Log.debug("Can't connect socket to ServerSocket"); ex.printStackTrace(); } try { sock.close(); } catch(Exception ex) { debug(ex.toString()); } if(!Settings.getFtpPasvMode()) { try { ssock.close(); } catch(Exception ex) { debug(ex.toString()); } } finished = true; if(ok) { con.fireProgressUpdate(file, FINISHED, -1); } else { con.fireProgressUpdate(file, FAILED, -1); } } public InputStream getInputStream() { return in; } public FtpConnection getCon() { return con; } private void debug(String msg) { Log.debug(msg); } public void reset() { reciever.destroy(); reciever = new Thread(this); reciever.start(); } private void pause(int time) { try { reciever.sleep(time); } catch(Exception ex) { System.out.println(ex); } } private boolean time() { long now = System.currentTimeMillis(); long offset = now - start; if(offset > Settings.statusMessageAfterMillis) { start = now; return true; } return false; } public boolean isThere() { if(finished) { return true; } return isThere; } public void setType(String tmp) { type = tmp; } public boolean isOK() { return ok; } public void interrupt() { if(Settings.getFtpPasvMode() && (type.equals(GET) || type.equals(GETDIR))) { try { reciever.join(); } catch(InterruptedException ex) { ex.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -