zipinputstream

How to read and extract zip entries from java.sql.Blob type zip file without having FileInputStream or filepath as a string java

依然范特西╮ 提交于 2021-02-04 08:33:04
问题 public static void unzipFiles(java.sql.Blob zip) throws Exception{ String paths = ""; byte[] blobAsBytes = zip.getBytes(1, (int) zip.length()); ZipInputStream zis = new ZipInputStream(zip.getBinaryStream(), StandardCharsets.UTF_8); ZipEntry zipEntry = null; while ((zipEntry = zis.getNextEntry()) != null) { paths=zipEntry.getName()+" "; } Connection conn = DriverManager.getConnection("jdbc:default:connection:"); String sql = "INSERT INTO E (FILENAME) VALUES (:paths)"; PreparedStatement pstmt =

Is there any way to upload extracted zip file using “java.util.zip” to AWS-S3 using multipart upload (Java high level API)

笑着哭i 提交于 2021-01-27 13:13:51
问题 Need to upload a large file to AWS S3 using multipart-upload using stream instead of using /tmp of lambda.The file is uploaded but not uploading completely. In my case the size of each file in zip cannot be predicted, may be a file goes up to 1 Gib of size.So I used ZipInputStream to read from S3 and I want to upload it back to S3.Since I am working on lambda, I cannot save the file in /tmp of lambda due to the large file size.So I tried to read and upload directly to S3 without saving in

Removing a jar files META-INF folder in Java

家住魔仙堡 提交于 2020-02-04 14:41:02
问题 I am using the following method to filter out META-INF folder and its contents: public static void copyWithoutMetaInf(final String originalZip, final String newZip) throws IOException { final ZipInputStream zip = new ZipInputStream(new FileInputStream(originalZip)); final ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(newZip)); ZipEntry entry; while((entry = zip.getNextEntry()) != null) { if(!entry.getName().contains("META-INF")) { zop.putNextEntry(entry); } } zip.close(); zop

Java InputStream read buffer

独自空忆成欢 提交于 2020-01-05 04:20:30
问题 Say I'm trying to read from a Java InputStream like this: ZipInputStream zis = new ZipInputStream(new FileInputStream("C:\\temp\\sample3.zip")); zis.getNextEntry(); byte[] buffer2 = new byte[2]; int count = zis.read(buffer2)); if(count != -1) //process... else...//something wrong, abort I'm parsing a binary file and I set my buffer to 2 in this case because I want to read the next short. I would set my buffer to size 4 if I want to read the next int and so on for other types. The problem is

Getting specific file from ZipInputStream

橙三吉。 提交于 2019-12-23 08:02:50
问题 I can go through ZipInputStream , but before starting the iteration I want to get a specific file that I need during the iteration. How can I do that? ZipInputStream zin = new ZipInputStream(myInputStream) while ((entry = zin.getNextEntry()) != null) { println entry.getName() } 回答1: If the myInputStream you're working with comes from a real file on disk then you can simply use java.util.zip.ZipFile instead, which is backed by a RandomAccessFile and provides direct access to the zip entries by

ZipInputStream(InputStream, Charset) decodes ZipEntry file name falsely

怎甘沉沦 提交于 2019-12-19 08:06:32
问题 Java 7 is supposed to fix an old problem with unpacking zip archives with character sets other than UTF-8. This can be achieved by constructor ZipInputStream(InputStream, Charset) . So far, so good. I can unpack a zip archive containing file names with umlauts in them when explicitly setting an ISO-8859-1 character set. But here is the problem: When iterating over the stream using ZipInputStream.getNextEntry() , the entries have wrong special characters in their names. In my case the umlaut

ZipInputStream(InputStream, Charset) decodes ZipEntry file name falsely

喜欢而已 提交于 2019-12-19 08:06:30
问题 Java 7 is supposed to fix an old problem with unpacking zip archives with character sets other than UTF-8. This can be achieved by constructor ZipInputStream(InputStream, Charset) . So far, so good. I can unpack a zip archive containing file names with umlauts in them when explicitly setting an ISO-8859-1 character set. But here is the problem: When iterating over the stream using ZipInputStream.getNextEntry() , the entries have wrong special characters in their names. In my case the umlaut

Extracting file with ZipInputStream error UTFDataFormatException

五迷三道 提交于 2019-12-17 20:54:08
问题 I have an error while I try to extract the files of a .zip that I have stored in my assets folder, the error appear because my file have the character ñ. The error throws when I try to get next entry: zipIs.getNextEntry() private void loadzip(String folder, InputStream inputStream) throws IOException { ZipInputStream zipIs = new ZipInputStream(inputStream); ZipEntry ze = null; int i=0; while ((ze = zipIs.getNextEntry()) != null) { FileOutputStream fout = new FileOutputStream(folder +"/"+ ze

Spring: how to parse uploaded zip file?

瘦欲@ 提交于 2019-12-12 20:08:05
问题 I uploaded my zip archive to the server and want to open .txt and .jpg files in it. I successfully get my archive in my Controller and get the name of each file via ZipEntry . Now I want to open it but for this I should get a full path to my file. I haven't found how I can do that. Could you suggest some approach how to do that ? Update I try to use example have been suggested below but I am not be able open the file ZipFile zFile = new ZipFile("trainingDefaultApp.zip"); I have got the

How can I avoid mutable variables in Scala when using ZipInputStreams and ZipOutpuStreams?

牧云@^-^@ 提交于 2019-12-12 08:19:29
问题 I'm trying to read a zip file, check that it has some required files, and then write all valid files out to another zip file. The basic introduction to java.util.zip has a lot of Java-isms and I'd love to make my code more Scala-native. Specifically, I'd like to avoid the use of vars . Here's what I have: val fos = new FileOutputStream("new.zip"); val zipOut = new ZipOutputStream(new BufferedOutputStream(fos)); while (zipIn.available == 1) { val entry = zipIn.getNextEntry if (entryIsValid