@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; }