直接读取ZIP包数据 线上、线下方法

public static void main(String[] args) {

       //

       String path = "C:\\Users\\hengy\\Desktop\\2019042414.zip";

       String dnFileUrl =

           "http://mbncontent.oss-ap-southeast-1.aliyuncs.com/TH/C792871848C74AC4/DN/2019042414.zip";

       ZipInputStream zipInputStream = null;

       BufferedReader br = null;

       try {

           // new

           URL url = new URL(dnFileUrl);

           //

           HttpURLConnection conn = (HttpURLConnection)url.openConnection();

           Charset utf8 = Charset.forName("UTF-8");

           int resultCode = conn.getResponseCode();

           if (HttpStatus.OK.value() == resultCode) {

               zipInputStream = new ZipInputStream(conn.getInputStream(), utf8);

               ZipEntry zipEntry;

               while ((zipEntry = zipInputStream.getNextEntry()) != null) {

                   if (zipEntry.toString().endsWith("txt")) {

                       br = new BufferedReader(new InputStreamReader(zipInputStream));

                       String line;

                       while ((line = br.readLine()) != null) {

                           String[] infoArr = line.toString().split(",");

                           if (null != infoArr && infoArr.length > 1) {

                               PayPigeonLeadsDnModel dnModel = new PayPigeonLeadsDnModel();

                               dnModel.setTelco(infoArr[0]);

                               dnModel.setShortcode(infoArr[1]);

                               dnModel.setKeyword(infoArr[2]);

                               dnModel.setMtid(infoArr[3]);

                               dnModel.setMsisdn(infoArr[4]);

                               dnModel.setStatus(infoArr[5]);

                               if (infoArr.length >= 7) {

                                   dnModel.setStatusDetails(infoArr[6]);

                               }

                               //

                               System.out.println(dnModel.toString());

 

                           }

                       }

 

                   }

                   System.out.println();

               }

           }

 

       } catch (Exception e) {

           e.printStackTrace();

           LOGGER.error("Read zip file error. : {}", e.getMessage());

       } finally {

           try {

               if (null != br) {

                   br.close();

               }

               if (null != zipInputStream) {

                   zipInputStream.close();

               }

           } catch (IOException e) {

               e.printStackTrace();

               LOGGER.error("close zipInputStream error. : {}", e.getMessage());

           }

       }

 

       // //

       // ZipFile zipFile;

       // ZipInputStream zipInputStream = null;

       // try {

       // zipFile = new ZipFile(dnFileUrl);

       //

       // InputStream inputStream = new BufferedInputStream(new FileInputStream(dnFileUrl));

       // Charset utf8 = Charset.forName("UTF-8");

       // zipInputStream = new ZipInputStream(inputStream, utf8);

       // ZipEntry zipEntry;

       // while ((zipEntry = zipInputStream.getNextEntry()) != null) {

       // if (zipEntry.toString().endsWith("txt")) {

       // BufferedReader br =

       // new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry)));

       // String line;

       // while ((line = br.readLine()) != null) {

       // String[] infoArr = line.toString().split(",");

       // if (null != infoArr && infoArr.length > 1) {

       // PayPigeonLeadsDnModel dnModel = new PayPigeonLeadsDnModel();

       // dnModel.setTelco(infoArr[0]);

       // dnModel.setShortcode(infoArr[1]);

       // dnModel.setKeyword(infoArr[2]);

       // dnModel.setMtid(infoArr[3]);

       // dnModel.setMsisdn(infoArr[4]);

       // dnModel.setStatus(infoArr[5]);

       // if (infoArr.length >= 7) {

       // dnModel.setStatusDetails(infoArr[6]);

       // }

       // //

       // System.out.println(dnModel.toString());

       //

       // }

       // }

       // br.close();

       // }

       // System.out.println();

       // }

       // } catch (IOException e) {

       // e.printStackTrace();

       // LOGGER.error("Read zip file error. : {}", e.getMessage());

       // } finally {

       // try {

       // if (null != zipInputStream) {

       // zipInputStream.closeEntry();

       // }

       // } catch (IOException e) {

       // e.printStackTrace();

       // LOGGER.error("close zipInputStream error. : {}", e.getMessage());

       // }

       // }

   }
posted @   xiexie0812  阅读(664)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示