private BinaryKey restoreBinaryFile( File binaryFile ) { if (!binaryFile.exists()) return null; if (!binaryFile.canRead()) { I18n msg = JcrI18n.problemsReadingBinaryFromBackup; BinaryKey key = binaryKeyFor(binaryFile, false); problems.addError(msg, key.toString(), repositoryName(), backupLocation()); } boolean isCompressed = FileUtil.getExtension(binaryFile.getAbsolutePath()).equals(GZIP_EXTENSION); try { InputStream stream = new FileInputStream(binaryFile); if(isCompressed){ stream = new GZIPInputStream(stream); } stream = new BufferedInputStream(stream); try { BinaryValue stored = binaryStore.storeValue(stream, isCompressed); assert stored.getKey().equals(binaryKeyFor(binaryFile, isCompressed)); return stored.getKey(); } finally { stream.close(); } } catch (Exception e) { // We already checked that it exists and is readable, so this shouldn't happen. But ... I18n msg = JcrI18n.problemsReadingBinaryFromBackup; BinaryKey key = binaryKeyFor(binaryFile, isCompressed); problems.addError(e, msg, key.toString(), repositoryName(), backupLocation()); return null; } }
private BinaryKey restoreBinaryFile( File binaryFile ) { if (!binaryFile.exists()) return null; if (!binaryFile.canRead()) { I18n msg = JcrI18n.problemsReadingBinaryFromBackup; BinaryKey key = binaryKeyFor(binaryFile, false); problems.addError(msg, key.toString(), repositoryName(), backupLocation()); } boolean isCompressed = FileUtil.getExtension(binaryFile.getAbsolutePath()).equals(GZIP_EXTENSION); try { InputStream stream = new FileInputStream(binaryFile); if(isCompressed){ stream = new GZIPInputStream(stream); } stream = new BufferedInputStream(stream); try { BinaryValue stored = binaryStore.storeValue(stream, isCompressed); assert stored.getKey().equals(binaryKeyFor(binaryFile, isCompressed)); return stored.getKey(); } finally { stream.close(); } } catch (Exception e) { // We already checked that it exists and is readable, so this shouldn't happen. But ... I18n msg = JcrI18n.problemsReadingBinaryFromBackup; BinaryKey key = binaryKeyFor(binaryFile, isCompressed); problems.addError(e, msg, key.toString(), repositoryName(), backupLocation()); return null; } }