免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6642 | 回复: 0

[FastDFS] 下载图片报错:java.io.IOException: recv package size -1 != 10 [复制链接]

论坛徽章:
0
发表于 2018-09-03 18:50 |显示全部楼层
在下载图片时,报错:java.io.IOException: recv package size -1 != 10。求各位大佬帮忙!!!!!!代码如下:

public class FastDFSUtil {
        private static Logger LOGGER = LoggerFactory.getLogger(FastDFSUtil.class);
        private static String classPath = FastDFSUtil.class.getProtectionDomain()
                        .getCodeSource().getLocation().getPath();
        private static String FASTDFS_CLIENT_CONF = classPath + "fdfs_client.conf";

        private static TrackerClient trackerClient = null;
        private static TrackerServer trackerServer = null;
        private static StorageClient storageClient = null;
        private static StorageServer storageServer = null;
        // 默认下载路径
        private static String DOWNLOAD_PATH = "D:/test_fastDFS/新建文件夹/download1";

        private FastDFSUtil() {
                FastDFSUtil.init();
        }

        private static void init() {
                try {
                        ClientGlobal.init(FASTDFS_CLIENT_CONF);
                        trackerClient = new TrackerClient();
                        trackerServer = trackerClient.getConnection();
                        storageServer = trackerClient.getStoreStorage(trackerServer);
                        storageClient = new StorageClient(trackerServer, storageServer);
                } catch (Exception e) {
                        throw new RuntimeException("init exception");
                }
        }
        public static FastDFSUtil getInstance() {
                return FastDFSUtilHolder.INSTANCE;
        }

        private static class FastDFSUtilHolder {
                private static final FastDFSUtil INSTANCE = new FastDFSUtil();
        }


        public static void download(String group, String file, String storePath) {
                boolean istrue=true;
                do{
                        try {
                                byte[] data = storageClient.download_file(group, file);
                                if (null != data){
                                        istrue=false;
                                }
                                File savefile = new File(storePath);
                                if (!savefile.exists()) {
                                        savefile.mkdirs();
                                }
                                IOUtils.write(data, new FileOutputStream(new File(storePath + "/"
                                                + file.substring(file.lastIndexOf("/") + 1))));
                                LOGGER.info("~~download success~~");

                        } catch (Exception e) {
                                e.printStackTrace();
                                throw new RuntimeException("download exception");
                        }
                }while(istrue);
               
        }
}

测试类:
public class TestFastDFS {

        public static String MAYDAY_IMG = "D:/Documents/Pictures/test2.jpg";

        public static String BASE_DOWNLOAD_PATH = "D:/test_fastDFS/新建文件夹/download2";

        public static void main(String[] args) {

                NameValuePair[] metaDataList = new NameValuePair[] {
                                new NameValuePair("width", "100"),
                                new NameValuePair("height", "100") };
                //NameValuePair[] metaDataList = null ;
                FastDFSUtil.getInstance();
                                                               
                // download group2/M00/00/00/wKgI21uNe1OAQpaiAAAlV5hH__M065.jpg
                FastDFSUtil.download("group1",
                                "M00/00/00/wKgI2VuNfBmANpG6AAB7lbxNbKo940.jpg",
                                BASE_DOWNLOAD_PATH);                               
        }

}


下载图片时,总是报错
报错信息如下:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.io.IOException: recv package size -1 != 10
        at org.csource.fastdfs.ProtoCommon.recvHeader(ProtoCommon.java:169)
        at org.csource.fastdfs.ProtoCommon.recvPackage(ProtoCommon.java:201)
        at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1125)
        at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1105)
        at com.sml.sz.fastdfs.FastDFSUtil.download(FastDFSUtil.java:153)
        at com.sml.sz.fastdfs.TestFastDFS.main(TestFastDFS.java:30)
Exception in thread "main" java.lang.RuntimeException: download exception
        at com.sml.sz.fastdfs.FastDFSUtil.download(FastDFSUtil.java:167)
        at com.sml.sz.fastdfs.TestFastDFS.main(TestFastDFS.java:30)



您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP