@Override public <T> List<T> readEntities(String fileName, Class<T> entityClass) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); this.decrypter.extractEntry(this.decrypter.getEntry(fileName), bos, this.password); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); T[] template = (T[]) Array.newInstance(entityClass, 0); T[] result = (T[])this.objectMapper.readValue(bis, template.getClass()); return Arrays.asList(result); } catch (Exception ioe) { throw new RuntimeException(ioe); } }
/** * extract zipEntry - uses in-memory, so your file should not be too big */ public void extractEntry(ExtZipEntry zipEntry, File outFile, String password) throws IOException, ZipException, DataFormatException { ByteArrayOutputStream bos = null; FileOutputStream fos = null; try { bos = new ByteArrayOutputStream(bufferSize); fos = new FileOutputStream(outFile); extractEntry(zipEntry, bos, password); byte[] buffer = bos.toByteArray(); fos.write(buffer); } finally { if (bos != null) { bos.close(); } if (fos != null) { fos.close(); } } }
/** * extract zipEntry - uses in-memory, so your file should not be too big */ public void extractEntry(ExtZipEntry zipEntry, File outFile, String password) throws IOException, ZipException, DataFormatException { ByteArrayOutputStream bos = null; FileOutputStream fos = null; try { bos = new ByteArrayOutputStream(bufferSize); fos = new FileOutputStream(outFile); extractEntry(zipEntry, bos, password); byte[] buffer = bos.toByteArray(); fos.write(buffer); } finally { if (bos != null) { bos.close(); } if (fos != null) { fos.close(); } } }