public static void writeToFile( FileSystemAbstraction fs, File file, byte[] bytes ) throws IOException { try ( OutputStream o = fs.openAsOutputStream( file, false ) ) { o.write( bytes ); } }
@Override public OutputStream openAsOutputStream( File fileName, boolean append ) throws IOException { return fs.openAsOutputStream( fileName, append ); }
@Override public OutputStream openAsOutputStream( File fileName, boolean append ) throws IOException { return delegate.openAsOutputStream( fileName, append ); }
/** * Creates a file, or opens an existing file. If necessary, parent directories will be created. * * @param fileSystem The filesystem abstraction to use * @param file The file to create or open * @return An output stream * @throws IOException If an error occurs creating directories or opening the file */ public static OutputStream createOrOpenAsOutputStream( FileSystemAbstraction fileSystem, File file, boolean append ) throws IOException { if ( file.getParentFile() != null ) { fileSystem.mkdirs( file.getParentFile() ); } return fileSystem.openAsOutputStream( file, append ); } }
static Writer create( FileSystemAbstraction fs, PageCache pages, File path, int pageSize ) throws IOException { if ( pages == null ) { return new StreamWriter( fs.openAsOutputStream( path, false ) ); } else if ( WRITE_TO_PAGE_CACHE ) { return new PageWriter( pages.map( path, pageSize ) ); } else { return new OpeningStreamWriter( fs.openAsOutputStream( path, false ), pages, path, pageSize ); } } }
private void copy( URL in, File outFile ) throws IOException { try ( InputStream is = in.openStream(); OutputStream os = fsa.openAsOutputStream( outFile, false ) ) { while ( is.available() > 0 ) { byte[] buf = new byte[8192]; int nBytes = is.read( buf ); os.write( buf, 0, nBytes ); } } } }
private void register( String test, String dir ) { try ( PrintStream printStream = new PrintStream( fileSystem.openAsOutputStream( new File( ensureBase(), ".register" ), true ) ) ) { printStream.print( format( "%s = %s%n", dir, test ) ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
@Override public OutputStream openAsOutputStream( File fileName, boolean append ) throws IOException { return chooseFileSystem( fileName ).openAsOutputStream( fileName, append ); }
private void backupCorruptedContent( long recoveredTransactionLogVersion, long recoveredTransactionOffset ) throws IOException { File corruptedLogArchive = getArchiveFile( recoveredTransactionLogVersion, recoveredTransactionOffset ); try ( ZipOutputStream recoveryContent = new ZipOutputStream( new BufferedOutputStream( fs.openAsOutputStream( corruptedLogArchive, false ) ) ) ) { ByteBuffer zipBuffer = ByteBuffer.allocate( (int) ByteUnit.mebiBytes( 1 ) ); copyTransactionLogContent( recoveredTransactionLogVersion, recoveredTransactionOffset, recoveryContent, zipBuffer ); forEachSubsequentLogFile( recoveredTransactionLogVersion, fileIndex -> { try { copyTransactionLogContent( fileIndex, 0, recoveryContent, zipBuffer ); } catch ( IOException io ) { throw new UncheckedIOException( io ); } } ); } }
private OutputStream badOutputFile() throws IOException { File badDataPath = new File( "/tmp/foo2" ).getAbsoluteFile(); FileSystemAbstraction fileSystem = fs.get(); File badDataFile = badDataFile( fileSystem, badDataPath ); return fileSystem.openAsOutputStream( badDataFile, true ); }
@Override public OutputStream openAsOutputStream( File fileName, boolean append ) throws IOException { // Default adversarial might throw a java.lang.SecurityException here, which is an exception // that should not be survived adversary.injectFailure( FileNotFoundException.class ); final OutputStream outputStream = delegate.openAsOutputStream( fileName, append ); return new AdversarialOutputStream( outputStream, adversary ) { @Override public void write( byte[] b ) throws IOException { // Default adversarial might throw a NullPointerException.class or IndexOutOfBoundsException here, // which are exceptions that should not be survived adversary.injectFailure( IOException.class ); outputStream.write( b ); } @Override public void write( byte[] b, int off, int len ) throws IOException { // Default adversarial might throw a NullPointerException.class or IndexOutOfBoundsException here, // which are exceptions that should not be survived adversary.injectFailure( IOException.class ); outputStream.write( b, off, len ); } }; }
@Override public OutputStream openAsOutputStream( File fileName, boolean append ) throws IOException { adversary.injectFailure( FileNotFoundException.class, SecurityException.class ); return new AdversarialOutputStream( delegate.openAsOutputStream( fileName, append ), adversary ); }
private File fileContaining( FileSystemAbstraction fs, String content ) throws IOException { File shortFile = directory.file( "file" ); fs.deleteFile( shortFile ); try ( OutputStream outputStream = fs.openAsOutputStream( shortFile, false ) ) { outputStream.write( UTF8.encode( content ) ); return shortFile; } } }
@Test void lastPageIdOfFileWithExactlyTwoPagesAndOneByteWorthOfDataIsTwo() throws IOException { configureStandardPageCache(); int twoPagesWorthOfRecords = recordsPerFilePage * 2; generateFileWithRecords( file( "a" ), twoPagesWorthOfRecords, recordSize ); OutputStream outputStream = fs.openAsOutputStream( file( "a" ), true ); outputStream.write( 'a' ); outputStream.close(); try ( PagedFile pagedFile = map( file( "a" ), filePageSize ) ) { assertThat( pagedFile.getLastPageId(), is( 2L ) ); } }
@Override public void afterEach( ExtensionContext context ) { Profiler profiler = getStoredValue( context ); try { profiler.finish(); if ( context.getExecutionException().isPresent() ) { ExtensionContext.Store testDirStore = getStore( context, TestDirectoryExtension.TEST_DIRECTORY_NAMESPACE ); TestDirectory testDir = (TestDirectory) testDirStore.get( TestDirectoryExtension.TEST_DIRECTORY ); File profileOutputFile = testDir.createFile( "profiler-output.txt" ); FileSystemAbstraction fs = testDir.getFileSystem(); try ( PrintStream out = new PrintStream( fs.openAsOutputStream( profileOutputFile, false ) ) ) { String displayName = context.getTestClass().map( Class::getSimpleName ).orElse( "class" ) + "." + context.getDisplayName(); profiler.printProfile( out, displayName ); } } } catch ( Exception e ) { throw new JUnitException( "Failed to finish profiling and/or produce profiling output.", e ); } } }
@Override public void doImport() throws IOException { FileSystemAbstraction fs = outsideWorld.fileSystem(); File storeDir = databaseConfig.get( GraphDatabaseSettings.database_path ); File logsDir = databaseConfig.get( GraphDatabaseSettings.logs_directory ); File reportFile = new File( reportFileName ); OutputStream badOutput = new BufferedOutputStream( fs.openAsOutputStream( reportFile, false ) ); Collector badCollector = badCollector( badOutput, isIgnoringSomething() ? BadCollector.UNLIMITED_TOLERANCE : 0, collect( ignoreBadRelationships, ignoreDuplicateNodes, ignoreExtraColumns ) ); Configuration configuration = new WrappedBatchImporterConfigurationForNeo4jAdmin( importConfiguration( null, false, databaseConfig, storeDir, highIO ) ); // Extract the default time zone from the database configuration ZoneId dbTimeZone = databaseConfig.get( GraphDatabaseSettings.db_temporal_timezone ); Supplier<ZoneId> defaultTimeZone = () -> dbTimeZone; CsvInput input = new CsvInput( nodeData( inputEncoding, nodesFiles ), defaultFormatNodeFileHeader( defaultTimeZone ), relationshipData( inputEncoding, relationshipsFiles ), defaultFormatRelationshipFileHeader( defaultTimeZone ), idType, new WrappedCsvInputConfigurationForNeo4jAdmin( csvConfiguration( args, false ) ), badCollector ); ImportTool.doImport( outsideWorld.errorStream(), outsideWorld.errorStream(), outsideWorld.inStream(), DatabaseLayout.of( storeDir ), logsDir, reportFile, fs, nodesFiles, relationshipsFiles, false, input, this.databaseConfig, badOutput, configuration, false ); }
File file2 = file( "b" ); long file2sizeBytes = (maxPageIdCursor1 + 17) * filePageSize2; try ( OutputStream outputStream = fs.openAsOutputStream( file2, false ) )
badOutput = new BufferedOutputStream( fs.openAsOutputStream( badFile, false ) );
public static void writeToFile( FileSystemAbstraction fs, File file, byte[] bytes ) throws IOException { try ( OutputStream o = fs.openAsOutputStream( file, false ) ) { o.write( bytes ); } }
@Override public OutputStream createStream( String destination ) throws IOException { return fs.openAsOutputStream( new File( storeDir, destination ), true ); } }