Skip to content

Commit

Permalink
Use static methods to construct stream to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Mar 20, 2018
1 parent 8665f4d commit 62c27e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Expand Up @@ -19,21 +19,36 @@
*/
package org.neo4j.causalclustering.catchup.storecopy;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.fs.OpenMode;
import org.neo4j.io.pagecache.PagedFile;

import static org.neo4j.io.IOUtils.closeAll;

public class StreamToDisk implements StoreFileStream
{
private WritableByteChannel writableByteChannel;
private List<AutoCloseable> closeables;

public StreamToDisk( WritableByteChannel writableByteChannel, AutoCloseable... closeables )
static StreamToDisk fromPagedFile( PagedFile pagedFile ) throws IOException
{
return new StreamToDisk( pagedFile.openWritableByteChannel(), pagedFile );
}

static StreamToDisk fromFile( FileSystemAbstraction fsa, File file ) throws IOException
{
return new StreamToDisk( fsa.open( file, OpenMode.READ_WRITE ) );
}

private StreamToDisk( WritableByteChannel writableByteChannel, AutoCloseable... closeables )
{
this.writableByteChannel = writableByteChannel;
this.closeables = new ArrayList<>();
Expand Down
Expand Up @@ -25,7 +25,6 @@

import org.neo4j.causalclustering.catchup.tx.FileCopyMonitor;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.fs.OpenMode;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.impl.store.StoreType;
Expand Down Expand Up @@ -56,11 +55,11 @@ public StoreFileStream acquire( String destination, int requiredAlignment ) thro
{
int filePageSize = pageCache.pageSize() - pageCache.pageSize() % requiredAlignment;
PagedFile pagedFile = pageCache.map( fileName, filePageSize, StandardOpenOption.CREATE );
return new StreamToDisk( pagedFile.openWritableByteChannel(), pagedFile );
return StreamToDisk.fromPagedFile( pagedFile );
}
else
{
return new StreamToDisk( fs.open( fileName, OpenMode.READ_WRITE ) );
return StreamToDisk.fromFile( fs, fileName );
}
}
}

0 comments on commit 62c27e3

Please sign in to comment.