| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.FileUtil; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | |
| | | System.out.println(entryNameList); |
| | | |
| | | /* |
| | | try (ZipFile zipFile = new ZipFile(tempFile.toFile())) { |
| | | ZipEntry entry = zipFile.getEntry(entryn); |
| | | InputStream ins = zipFile.getInputStream(entry); |
| | | |
| | | Path outputPath = Paths.get("d:/downtest.txt"); |
| | | Files.copy(ins, outputPath, StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | |
| | | List<String> entryNameList = new ArrayList<>(); |
| | | try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes); |
| | | ZipFile zipFile = new ZipFile(channel)) { |
| | | |
| | | ZipArchiveEntry entry; |
| | | Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); |
| | | String entryn = "CP1-13-1/CP1-13-1-1-1-1.txt"; |
| | | while (entries.hasMoreElements()) { |
| | | entry = entries.nextElement(); |
| | | entryNameList.add(entry.getName()); |
| | | } |
| | | }*/ |
| | | /* |
| | | try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes); |
| | | ZipFile zipFile = new ZipFile(channel)) { |
| | | List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList(); |
| | | for(String dir : dirList) { |
| | | entryNameList.stream().filter(s -> s.startsWith(dir)).forEach(entryName -> { |
| | | ZipArchiveEntry fileEntry = zipFile.getEntry(entryName); |
| | | //ZipArchiveEntry fileEntry = entryMap.get(entryName); |
| | | String fileName = StringUtils.removeStart(entryName,dir);//去除文件名路径部分 |
| | | try { |
| | | InputStream ins = zipFile.getInputStream(fileEntry); |
| | | ByteArrayInputStream byteS = new ByteArrayInputStream(ins.readAllBytes()); |
| | | |
| | | Path outputPath = Paths.get("d:/downtest.txt"); |
| | | Files.copy(byteS, outputPath, StandardCopyOption.REPLACE_EXISTING); |
| | | byteS.reset(); |
| | | |
| | | BladeFile newOssFile = ossTemplate.putFile("mdm", fileName, byteS); |
| | | r.setData(newOssFile.getName()); |
| | | System.out.println(newOssFile.getName()); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | }); |
| | | } |
| | | }*/ |
| | | return r; |
| | | } |
| | | |
| | | @GetMapping("/replace") |
| | | @ApiOperationSupport(order = 2) |
| | | @Operation(summary = "替换内容") |
| | | public R<String> replace(String filepath) throws IOException { |
| | | File file = new File(filepath); |
| | | FileInputStream fis = new FileInputStream(file); |
| | | InputStream newins = FileContentUtil.replaceAtLine(fis,2,"GHTEST"); |
| | | |
| | | BladeFile bfile = ossTemplate.putFile("replaceok.txt",newins); |
| | | return R.data(bfile.getLink()+","+bfile.getName()); |
| | | } |
| | | |
| | | } |