📄 recvingfile.java
字号:
/* * RecvingFile.java * * Created on 2008年10月29日, 下午4:27 */package ipmsg.gui;import ipmsg.etc.Command;import ipmsg.etc.FileLinkList;import ipmsg.etc.FileNode;import ipmsg.etc.GlobalConstant;import ipmsg.etc.GlobalVar;import ipmsg.network.UtilityNet;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.net.Socket;import javax.swing.JScrollBar;import javax.swing.SwingUtilities;/** * * @author Noeru */public class RecvingFile extends javax.swing.JFrame { /** Creates new form RecvingFile */ private FileLinkList flist; private int fileSelection; private String savePath; InterfaceSetVisible_GetRecFiles inter; boolean replace; boolean cancelSafe=false; boolean cancelNow=false; private Socket socket; private DataInputStream inputStream; private DataOutputStream outputStream; private DataOutputStream fileOut; public RecvingFile(FileLinkList flist,int fileSelection, String savePath,InterfaceSetVisible_GetRecFiles inter, boolean replace) { this.fileSelection=fileSelection; this.flist=flist; this.savePath=savePath; this.replace=replace; this.inter=inter; initComponents(); new Thread(new RecvingDeamon()).start(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jPanel2 = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jToggleButton1 = new javax.swing.JToggleButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle("接收文件"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("接收文件列表")); jTextArea1.setColumns(20); jTextArea1.setEditable(false); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE) ); getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); jButton1.setText("立即终止"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("安全终止"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jLabel1.setText("0%"); jToggleButton1.setText("关闭输出"); jToggleButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jToggleButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jToggleButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2) .addComponent(jButton1) .addComponent(jLabel1) .addComponent(jToggleButton1)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-376)/2, (screenSize.height-277)/2, 376, 277); }// </editor-fold>//GEN-END:initComponentsprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed// TODO add your handling code here: this.exit();}//GEN-LAST:event_jButton1ActionPerformedprivate void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed// TODO add your handling code here: this.cancelSafe=true;}//GEN-LAST:event_jButton2ActionPerformedprivate void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing// TODO add your handling code here: this.exit();}//GEN-LAST:event_formWindowClosingprivate void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed// TODO add your handling code here: if(jToggleButton1.isSelected()){ this.jToggleButton1.setText("开启输出"); }else{ this.jToggleButton1.setText("关闭输出"); }}//GEN-LAST:event_jToggleButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JToggleButton jToggleButton1; // End of variables declaration//GEN-END:variables private void exit(){ if (!UtilityGui.confirm(this, "立即终止", "正在传输中,是否继续?")) { return; } this.cancelNow=true; this.dispose(); this.closeSocket(); this.exitNormal(); } class RecvingDeamon extends Thread{ @Override public void run() { Command com = new Command(GlobalConstant.IPMSG_GETFILEDATA); try { if (fileSelection == flist.getFiles().size()) { for (int i = 0; i < fileSelection; i++) { //如果已近接受过,则无需接收。 if(flist.getFiles().get(i).isIsTransfered())continue; initSocket(); //发送请求 com.setAdditional(Integer.toHexString( flist.getPacketNo()) + ":" + Integer.toHexString(i) + ":" + Integer.toHexString(0) + ":"); //如果是文件 if (flist.getFiles().get(i).getFileKind() == GlobalConstant.IPMSG_FILE_REGULAR) { com.resetFlag(GlobalConstant.IPMSG_GETFILEDATA); outputStream.write(com.exportToBuf()); outputStream.flush(); /*this.getRegularFile(savePath + GlobalVar.FILE_PATH_DELIMITER + flist.getFiles().get(i).getFileName(), flist.getFiles().get(i).getFileLen());*/ this.getRegularFile( this.getPath(savePath, flist.getFiles().get(i).getFileName()), flist.getFiles().get(i).getFileLen()); //如果是目录 } else if (flist.getFiles().get(i).getFileKind() == GlobalConstant.IPMSG_FILE_DIR){ com.resetFlag(GlobalConstant.IPMSG_GETDIRFILES); outputStream.write(com.exportToBuf()); outputStream.flush(); this.getDir(); } closeSocket(); if(!cancelNow)flist.getFiles().get(i).setIsTransfered(true); if(cancelSafe)break; } //设置已经全部传输 //flist.transferALL();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -