java中的isconnected_Java IoSession.isConnected方法代码示例

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类

@Override

public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws SSLException {

if (LOGGER.isDebugEnabled()) {

LOGGER.debug("{}: Writing Message : {}", getSessionInfo(session), writeRequest);

}

boolean needsFlush = true;

SslHandler handler = getSslSessionHandler(session);

synchronized (handler) {

if (!isSslStarted(session)) {

handler.scheduleFilterWrite(nextFilter, writeRequest);

}

// Don't encrypt the data if encryption is disabled.

else if (session.containsAttribute(DISABLE_ENCRYPTION_ONCE)) {

// Remove the marker attribute because it is temporary.

session.removeAttribute(DISABLE_ENCRYPTION_ONCE);

handler.scheduleFilterWrite(nextFilter, writeRequest);

} else {

// Otherwise, encrypt the buffer.

IoBuffer buf = (IoBuffer) writeRequest.getMessage();

if (handler.isWritingEncryptedData()) {

// data already encrypted; simply return buffer

handler.scheduleFilterWrite(nextFilter, writeRequest);

} else if (handler.isHandshakeComplete()) {

// SSL encrypt

int pos = buf.position();

handler.encrypt(buf.buf());

buf.position(pos);

IoBuffer encryptedBuffer = handler.fetchOutNetBuffer();

handler.scheduleFilterWrite(nextFilter, new EncryptedWriteRequest(writeRequest, encryptedBuffer));

} else {

if (session.isConnected()) {

// Handshake not complete yet.

handler.schedulePreHandshakeWriteRequest(nextFilter, writeRequest);

}

needsFlush = false;

}

}

}

if (needsFlush) {

handler.flushScheduledEvents();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 Android ftp 断点续传的 Java 代码示例: ```java import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class FtpUtil { private static final int BUFFER_SIZE = 1024 * 1024; public static boolean uploadFile(String host, int port, String username, String password, String remoteDir, String remoteFileName, String localFilePath) { FTPClient ftpClient = new FTPClient(); boolean success = false; try { ftpClient.connect(host, port); ftpClient.login(username, password); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); File localFile = new File(localFilePath); InputStream inputStream = new FileInputStream(localFile); ftpClient.changeWorkingDirectory(remoteDir); ftpClient.setControlEncoding("UTF-8"); ftpClient.setBufferSize(BUFFER_SIZE); long remoteSize = 0; FTPFile[] files = ftpClient.listFiles(remoteFileName); if (files.length == 1) { remoteSize = files[0].getSize(); } OutputStream outputStream = ftpClient.appendFileStream(remoteFileName); if (outputStream == null) { outputStream = ftpClient.storeFileStream(remoteFileName); } byte[] bytes = new byte[BUFFER_SIZE]; int length; long step = localFile.length() / 100; long process = remoteSize / step; while ((length = inputStream.read(bytes)) != -1) { outputStream.write(bytes, 0, length); remoteSize += length; long currentProcess = remoteSize / step; if (currentProcess > process) { process = currentProcess; if (process % 10 == 0) { System.out.println("上传进度:" + process); } } } outputStream.flush(); inputStream.close(); outputStream.close(); success = ftpClient.completePendingCommand(); } catch (IOException e) { e.printStackTrace(); } finally { if (ftpClient.isConnected()) { try { ftpClient.logout(); ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); } } } return success; } } ``` 希望能够帮到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值