@SuppressWarnings("unchecked") private O createArchiveOutputStream(boolean overwrite) throws IOException { O archiveOut; FileOutputStream out; if (!file.exists() || file.length() == 0 || overwrite) { out = new FileOutputStream(file); } else { throw new FileNotFoundException( "can't open for output, check existence or access rights: " + file.getAbsolutePath()); } String pathStr = path.toString(); Set<String> streamCodecs = CompressCodecService.getCodecs(); for (String codec : streamCodecs) { if (pathStr.endsWith("." + codec)) { archiveOut = (O) archiveService .getCodec(getName()) .createArchiveOutputStream(codecService.getCodec(codec).encode(out)); archiveOut.setWatcher(watcher); return archiveOut; } } archiveOut = (O) archiveService.getCodec(getName()).createArchiveOutputStream(out); archiveOut.setWatcher(watcher); return archiveOut; }
@SuppressWarnings("unchecked") private I createArchiveInputStream() throws IOException { I archiveIn; FileInputStream in; if (file.isFile() && file.canRead()) { in = new FileInputStream(file); } else { throw new FileNotFoundException( "can't open for input, check existence or access rights: " + path); } String pathStr = path.toString(); Set<String> streamCodecs = CompressCodecService.getCodecs(); for (String codec : streamCodecs) { if (pathStr.endsWith("." + codec)) { archiveIn = (I) archiveService .getCodec(getName()) .createArchiveInputStream(codecService.getCodec(codec).decode(in)); archiveIn.setWatcher(watcher); return archiveIn; } } archiveIn = (I) archiveService.getCodec(getName()).createArchiveInputStream(in); archiveIn.setWatcher(watcher); return archiveIn; }