@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); } }
public EncryptedZIPImportReader(String zipFileName, String password) { try { this.zipFile = new File(zipFileName); if (!zipFile.exists()) { throw new IllegalStateException("File " + zipFileName + " doesn't exists"); } this.objectMapper = JsonSerialization.mapper; AESDecrypter decrypter = new AESDecrypterBC(); this.decrypter = new AesZipFileDecrypter(this.zipFile, decrypter); this.password = password; } catch (IOException ioe) { throw new RuntimeException(ioe); } }
public ExtZipEntry getEntry( String name ) throws IOException, ZipException, DataFormatException { for( ExtZipEntry zipEntry : getEntryList() ) { if( name.equals(zipEntry.getName()) ) { return zipEntry; } } return null; }
public void extractEntryWithTmpFile( ExtZipEntry zipEntry, File outFile, String password ) throws IOException, ZipException, DataFormatException { checkZipEntry(zipEntry); makeDir( new File(tmpFile.getParent()) );
/** * 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(); } } }
protected static void makeDir(String dirStr) { if(dirStr!=null) { makeDir(new File(dirStr)); } }
checkZipEntry(zipEntry);
public AesZipFileDecrypter( File zipFile, AESDecrypter decrypter ) throws IOException { this.zipFile = zipFile; this.decrypter = decrypter; this.raFile = new ExtRandomAccessFile( zipFile ); initDirOffsetPosAndComment(); }
List<ExtZipEntry> out = new ArrayList<ExtZipEntry>(); short totalNumberOfEntries = this.getNumberOfEntries(); final int dirOffset = raFile.readInt( this.dirOffsetPos );
@Override public void closeImportReader() { try { this.decrypter.close(); } catch (Exception ioe) { throw new RuntimeException(ioe); } } }
fileZippedData = azfd.extractEntryToZippedByteArray(entry, password.toString(), new AesZipFileDecrypter.ProgressListener() {
public void extractEntryWithTmpFile( ExtZipEntry zipEntry, File outFile, String password ) throws IOException, ZipException, DataFormatException { checkZipEntry(zipEntry); makeDir( tmpFile.getParent() );
/** * 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(); } } }
protected static void makeDir(File dir) { if( dir!=null ) { if( !dir.exists() ) { if( dir.getParent()!=null ) { File parentDir = new File(dir.getParent()); if( !parentDir.exists() ) { makeDir(parentDir); } } dir.mkdir(); } } }
public AesZipFileDecrypter( File zipFile, AESDecrypter decrypter ) throws IOException { this.zipFile = zipFile; this.decrypter = decrypter; this.raFile = new ExtRandomAccessFile( zipFile ); initDirOffsetPosAndComment(); }
List<ExtZipEntry> out = new ArrayList<ExtZipEntry>(); short totalNumberOfEntries = this.getNumberOfEntries(); final int dirOffset = raFile.readInt( this.dirOffsetPos );
private ExtZipEntry findZipEntry(String regex) throws IOException { for(ExtZipEntry ze : azfd.getEntryList()) { if(ze.getName().matches(regex)) return ze; } return null; }
protected static void makeDir(File dir) { if( dir!=null ) { if( !dir.exists() ) { if( dir.getParent()!=null ) { File parentDir = new File(dir.getParent()); if( !parentDir.exists() ) { makeDir(parentDir); } } dir.mkdir(); } } }