// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java
// public interface Connection extends Closeable {
//     /**
//      * 关闭连接
//      */
//     @Override
//     void close();
// 
//     /**
//      * 连接是否关闭
//      *
//      * @return 返回true表示连接关闭
//      */
//     boolean isClosed();
// 
//     /**
//      * 测试连接是否有效
//      *
//      * @return 返回true表示连接无效
//      */
//     boolean isValid();
// 
//     /**
//      * 获取输出流
//      *
//      * @return 输出流
//      * @throws IOException 操作异常
//      */
//     OutputStream getOutputStream() throws IOException;
// 
//     /**
//      * 获取输入流
//      *
//      * @return 输入流
//      * @throws IOException 获取输入流错误
//      */
//     InputStream getInputStream() throws IOException;
// 
//     /**
//      * 获取字符集
//      *
//      * @return 字符集
//      */
//     Charset getCharset();
// }
// 
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadFileWriter.java
// public class DownloadFileWriter implements DownloadCallback<String> {
// 
//     /**
//      * 文件名称
//      */
//     private String fileName;
// 
//     public DownloadFileWriter(String fileName) {
//         this.fileName = fileName;
//     }
// 
//     /**
//      * 文件下载处理
//      *
//      * @return 返回文件名称
//      */
//     @Override
//     public String receive(InputStream inputStream) throws IOException {
//         FileOutputStream out = null;
//         InputStream in = null;
//         try {
//             out = new FileOutputStream(fileName);
//             in = new BufferedInputStream(inputStream);
//             // 通过ioutil 对接输入输出流，实现文件下载
//             IOUtils.copy(in, out);
//             out.flush();
//         } finally {
//             // 关闭流
//             IOUtils.closeQuietly(in);
//             IOUtils.closeQuietly(out);
//         }
//         return fileName;
//     }
// }
// 
// Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetGroupListCommandTest.java
// public class GetGroupListCommandTest {
//     /**
//      * 日志
//      */
//     private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class);
// 
//     @Test
//     public void test01() {
//         Connection connection = GetTrackerConnection.getDefaultConnection();
//         try {
//             GetGroupListCommand command = new GetGroupListCommand();
//             List<GroupState> list = command.execute(connection);
//             for (GroupState groupState : list) {
//                 logger.debug(groupState.toString());
//             }
//         } finally {
//             connection.close();
//         }
//     }
// }
// 
// Path: src/test/java/org/cleverframe/fastdfs/testbase/GetStorageConnection.java
// public class GetStorageConnection {
//     private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 23000);
//     private static final int soTimeout = 1500;
//     private static final int connectTimeout = 600;
//     private static final Charset charset = Charset.forName("UTF-8");
// 
//     public static Connection getDefaultConnection() {
//         return new SocketConnection(address, soTimeout, connectTimeout, charset);
//     }
// }


import org.cleverframe.fastdfs.conn.Connection;
import org.cleverframe.fastdfs.protocol.storage.callback.DownloadFileWriter;
import org.cleverframe.fastdfs.protocol.tracker.GetGroupListCommandTest;
import org.cleverframe.fastdfs.testbase.GetStorageConnection;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
        Connection connection = GetStorageConnection.getDefaultConnection();
        try {
            DownloadFileWriter callback = new DownloadFileWriter("Test.jpg");
            DownloadFileCommand<String> command = new DownloadFileCommand<String>("group1", "M00/00/00/wKg4i1gw1JWALQsHAATA4WNjQT4937_big.jpg", callback);
            String fileName = command.execute(connection);
        } finally {
            connection.close();
        }
    }

    @Test
    public void test02() {
        File file = new File("Test.jpg");
        logger.info(file.getAbsolutePath());
    }

    @Test
    public void test03() {
        List<Connection> connectionList = new ArrayList<Connection>();
        for (int i = 0; i < 1000; i++) {
            try {
                Connection connection = GetStorageConnection.getDefaultConnection();
                connectionList.add(connection);
                logger.info("新建连接数:" + i);
            } catch (Throwable e) {
                logger.info("连接异常");
                break;
            }
        }

// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java
// public interface Connection extends Closeable {
//     /**
//      * 关闭连接
//      */
//     @Override
//     void close();
// 
//     /**
//      * 连接是否关闭
//      *
//      * @return 返回true表示连接关闭
//      */
//     boolean isClosed();
// 
//     /**
//      * 测试连接是否有效
//      *
//      * @return 返回true表示连接无效
//      */
//     boolean isValid();
// 
//     /**
//      * 获取输出流
//      *
//      * @return 输出流
//      * @throws IOException 操作异常
//      */
//     OutputStream getOutputStream() throws IOException;
// 
//     /**
//      * 获取输入流
//      *
//      * @return 输入流
//      * @throws IOException 获取输入流错误
//      */
//     InputStream getInputStream() throws IOException;
// 
//     /**
//      * 获取字符集
//      *
//      * @return 字符集
//      */
//     Charset getCharset();
// }
// 
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadFileWriter.java
// public class DownloadFileWriter implements DownloadCallback<String> {
// 
//     /**
//      * 文件名称
//      */
//     private String fileName;
// 
//     public DownloadFileWriter(String fileName) {
//         this.fileName = fileName;
//     }
// 
//     /**
//      * 文件下载处理
//      *
//      * @return 返回文件名称
//      */
//     @Override
//     public String receive(InputStream inputStream) throws IOException {
//         FileOutputStream out = null;
//         InputStream in = null;
//         try {
//             out = new FileOutputStream(fileName);
//             in = new BufferedInputStream(inputStream);
//             // 通过ioutil 对接输入输出流，实现文件下载
//             IOUtils.copy(in, out);
//             out.flush();
//         } finally {
//             // 关闭流
//             IOUtils.closeQuietly(in);
//             IOUtils.closeQuietly(out);
//         }
//         return fileName;
//     }
// }
// 
// Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetGroupListCommandTest.java
// public class GetGroupListCommandTest {
//     /**
//      * 日志
//      */
//     private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class);
// 
//     @Test
//     public void test01() {
//         Connection connection = GetTrackerConnection.getDefaultConnection();
//         try {
//             GetGroupListCommand command = new GetGroupListCommand();
//             List<GroupState> list = command.execute(connection);
//             for (GroupState groupState : list) {
//                 logger.debug(groupState.toString());
//             }
//         } finally {
//             connection.close();
//         }
//     }
// }
// 
// Path: src/test/java/org/cleverframe/fastdfs/testbase/GetStorageConnection.java
// public class GetStorageConnection {
//     private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 23000);
//     private static final int soTimeout = 1500;
//     private static final int connectTimeout = 600;
//     private static final Charset charset = Charset.forName("UTF-8");
// 
//     public static Connection getDefaultConnection() {
//         return new SocketConnection(address, soTimeout, connectTimeout, charset);
//     }
// }


// Path: src/test/java/org/cleverframe/fastdfs/protocol/storage/DownloadFileCommandTest.java
import org.cleverframe.fastdfs.conn.Connection;
import org.cleverframe.fastdfs.protocol.storage.callback.DownloadFileWriter;
import org.cleverframe.fastdfs.protocol.tracker.GetGroupListCommandTest;
import org.cleverframe.fastdfs.testbase.GetStorageConnection;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

        Connection connection = GetStorageConnection.getDefaultConnection();
        try {
            DownloadFileWriter callback = new DownloadFileWriter("Test.jpg");
            DownloadFileCommand<String> command = new DownloadFileCommand<String>("group1", "M00/00/00/wKg4i1gw1JWALQsHAATA4WNjQT4937_big.jpg", callback);
            String fileName = command.execute(connection);
        } finally {
            connection.close();
        }
    }

    @Test
    public void test02() {
        File file = new File("Test.jpg");
        logger.info(file.getAbsolutePath());
    }

    @Test
    public void test03() {
        List<Connection> connectionList = new ArrayList<Connection>();
        for (int i = 0; i < 1000; i++) {
            try {
                Connection connection = GetStorageConnection.getDefaultConnection();
                connectionList.add(connection);
                logger.info("新建连接数:" + i);
            } catch (Throwable e) {
                logger.info("连接异常");
                break;
            }
        }

        for (Connection connection : connectionList) {