|
19 | 19 | import org.apache.commons.compress.archivers.ArchiveStreamFactory; |
20 | 20 | import org.apache.commons.compress.archivers.tar.TarArchiveEntry; |
21 | 21 | import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; |
| 22 | +import org.apache.commons.io.FileSystem; |
22 | 23 | import org.apache.commons.io.FileUtils; |
23 | 24 | import org.apache.commons.io.IOUtils; |
24 | 25 | import org.apache.commons.lang3.StringUtils; |
|
27 | 28 | import org.apache.pdfbox.Loader; |
28 | 29 | import org.apache.pdfbox.pdmodel.PDDocument; |
29 | 30 | import org.apache.pdfbox.text.PDFTextStripper; |
30 | | -import org.apache.poi.xssf.streaming.SXSSFRow; |
31 | | -import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
32 | 31 | import org.bouncycastle.jce.provider.BouncyCastleProvider; |
33 | 32 | import org.bouncycastle.openpgp.PGPCompressedData; |
34 | 33 | import org.bouncycastle.openpgp.PGPEncryptedDataList; |
|
41 | 40 | import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder; |
42 | 41 | import org.bouncycastle.util.io.Streams; |
43 | 42 | import org.jetbrains.annotations.NotNull; |
44 | | -import org.labkey.serverapi.reader.Readers; |
45 | 43 | import org.openqa.selenium.NotFoundException; |
46 | 44 |
|
47 | 45 | import java.io.BufferedInputStream; |
48 | 46 | import java.io.BufferedOutputStream; |
49 | | -import java.io.BufferedReader; |
50 | 47 | import java.io.ByteArrayInputStream; |
51 | 48 | import java.io.File; |
52 | 49 | import java.io.FileInputStream; |
|
71 | 68 | import java.util.List; |
72 | 69 | import java.util.Set; |
73 | 70 | import java.util.TreeSet; |
| 71 | +import java.util.regex.Pattern; |
74 | 72 | import java.util.stream.Collectors; |
75 | 73 | import java.util.zip.GZIPInputStream; |
76 | 74 | import java.util.zip.ZipEntry; |
@@ -707,34 +705,15 @@ public static byte[] decrypt(byte[] encrypted, char[] passPhrase) throws IOExcep |
707 | 705 | return Streams.readAll(ld.getInputStream()); |
708 | 706 | } |
709 | 707 |
|
| 708 | + private static final Pattern badChars = Pattern.compile("[\\\\:/\\[\\]?*|]"); |
710 | 709 |
|
711 | | - public static File convertTabularToXlsx(File tabularFile, String delimiter, String sheetName, String xlsxFileName) throws IOException, PGPException |
| 710 | + /** |
| 711 | + * Determining expected file names for downloaded files that are named according to some |
| 712 | + * value that might include characters that are not legal for files |
| 713 | + * @see FileSystem#toLegalFileName(String, char) |
| 714 | + */ |
| 715 | + public static String makeLegalFileName(String candidate) |
712 | 716 | { |
713 | | - File excelFile = new File(getTestTempDir(), xlsxFileName); |
714 | | - FileUtils.forceMkdirParent(excelFile); |
715 | | - |
716 | | - try(SXSSFWorkbook workBook = new SXSSFWorkbook(1000); // holds 1000 rows at a time |
717 | | - BufferedReader br = Readers.getReader(tabularFile); |
718 | | - FileOutputStream out = new FileOutputStream(excelFile)) |
719 | | - { |
720 | | - var sheet = workBook.createSheet(sheetName); |
721 | | - |
722 | | - String currentLine; |
723 | | - int rowNum=0; |
724 | | - |
725 | | - while ((currentLine = br.readLine()) != null) |
726 | | - { |
727 | | - String str[] = currentLine.split(delimiter); |
728 | | - SXSSFRow currentRow = sheet.createRow(rowNum); |
729 | | - for (int i = 0; i < str.length; i++) |
730 | | - { |
731 | | - currentRow.createCell(i).setCellValue(str[i]); |
732 | | - } |
733 | | - rowNum++; |
734 | | - } |
735 | | - workBook.write(out); // flush remaining rows |
736 | | - } |
737 | | - |
738 | | - return excelFile; |
| 717 | + return badChars.matcher(candidate).replaceAll("_"); |
739 | 718 | } |
740 | 719 | } |
0 commit comments