/** * Decompress gzip archive. */ public static File ungzip(String file) throws IOException { return ungzip(new File(file)); }
/** * Decompress gzip archive. */ public static File ungzip(final String file) throws IOException { return ungzip(new File(file)); }
@Test void testGzip() throws IOException { ZipUtil.gzip(new File(dataRoot, "sb.data")); File gzipFile = new File(dataRoot, "sb.data.gz"); assertTrue(gzipFile.exists()); FileUtil.move(gzipFile, new File(dataRoot, "sb2.data.gz")); ZipUtil.ungzip(new File(dataRoot, "sb2.data.gz")); File data = new File(dataRoot, "sb2.data"); assertTrue(data.exists()); byte[] data2Bytes = FileUtil.readBytes(data); byte[] data1Bytes = FileUtil.readBytes(new File(dataRoot, "sb.data")); assertTrue(Arrays.equals(data1Bytes, data2Bytes)); // cleanup FileUtil.delete(new File(dataRoot, "sb2.data")); FileUtil.delete(new File(dataRoot, "sb2.data.gz")); }
/** * Decompress gzip archive. */ public static File ungzip(final String file) throws IOException { return ungzip(new File(file)); }
private String handleGzipBill(String url, String requestStr) { try { byte[] responseBytes = this.postForBytes(url, requestStr, false); Path tempDirectory = Files.createTempDirectory("bill"); Path path = Paths.get(tempDirectory.toString(), System.currentTimeMillis() + ".gzip"); Files.write(path, responseBytes); try { List<String> allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8); return Joiner.on("\n").join(allLines); } catch (ZipException e) { if (e.getMessage().contains("Not in GZIP format")) { throw WxPayException.from(BaseWxPayResult.fromXML(new String(responseBytes, StandardCharsets.UTF_8), WxPayCommonResult.class)); } else { this.log.error("解压zip文件出错", e); } } } catch (Exception e) { this.log.error("解析对账单文件时出错", e); } return null; }
private String handleGzipBill(String url, String requestStr) { try { byte[] responseBytes = this.postForBytes(url, requestStr, false); Path tempDirectory = Files.createTempDirectory("bill"); Path path = Paths.get(tempDirectory.toString(), System.currentTimeMillis() + ".gzip"); Files.write(path, responseBytes); try { List<String> allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8); return Joiner.on("\n").join(allLines); } catch (ZipException e) { if (e.getMessage().contains("Not in GZIP format")) { throw WxPayException.from(BaseWxPayResult.fromXML(new String(responseBytes, StandardCharsets.UTF_8), WxPayCommonResult.class)); } else { this.log.error("解压zip文件出错", e); } } } catch (Exception e) { this.log.error("解析对账单文件时出错", e); } return null; }
private String handleGzipFundFlow(String url, String requestStr) throws WxPayException { try { byte[] responseBytes = this.postForBytes(url, requestStr, true); Path tempDirectory = Files.createTempDirectory("fundFlow"); Path path = Paths.get(tempDirectory.toString(), System.currentTimeMillis() + ".gzip"); Files.write(path, responseBytes); try { List<String> allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8); return Joiner.on("\n").join(allLines); } catch (ZipException e) { if (e.getMessage().contains("Not in GZIP format")) { throw WxPayException.from(BaseWxPayResult.fromXML(new String(responseBytes, StandardCharsets.UTF_8), WxPayCommonResult.class)); } else { this.log.error("解压zip文件出错", e); throw new WxPayException("解压zip文件出错"); } } } catch (WxPayException wxPayException) { throw wxPayException; } catch (Exception e) { this.log.error("解析对账单文件时出错", e); throw new WxPayException("解压zip文件出错"); } }
private String handleGzipFundFlow(String url, String requestStr) throws WxPayException { try { byte[] responseBytes = this.postForBytes(url, requestStr, true); Path tempDirectory = Files.createTempDirectory("fundFlow"); Path path = Paths.get(tempDirectory.toString(), System.currentTimeMillis() + ".gzip"); Files.write(path, responseBytes); try { List<String> allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8); return Joiner.on("\n").join(allLines); } catch (ZipException e) { if (e.getMessage().contains("Not in GZIP format")) { throw WxPayException.from(BaseWxPayResult.fromXML(new String(responseBytes, StandardCharsets.UTF_8), WxPayCommonResult.class)); } else { this.log.error("解压zip文件出错", e); throw new WxPayException("解压zip文件出错"); } } } catch (WxPayException wxPayException) { throw wxPayException; } catch (Exception e) { this.log.error("解析对账单文件时出错", e); throw new WxPayException("解压zip文件出错"); } }