Package nbbrd.io
Class BlockSizer
- java.lang.Object
-
- nbbrd.io.BlockSizer
-
public class BlockSizer extends Object
System-wide utility that gets the number of bytes per block from several byte sources. May be overridden to deal with new JDK APIs.
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_BLOCK_BUFFER_SIZEstatic longDEFAULT_BUFFER_OUTPUT_STREAM_SIZEstatic AtomicReference<BlockSizer>INSTANCEstatic longUNKNOWN_SIZE
-
Constructor Summary
Constructors Constructor Description BlockSizer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetBlockSize(InputStream stream)Returns the number of bytes per block in the input stream implementation.longgetBlockSize(OutputStream stream)Returns the number of bytes per block in the output stream implementation.longgetBlockSize(Path file)Returns the number of bytes per block in the file store of this file.
-
-
-
Field Detail
-
INSTANCE
public static final AtomicReference<BlockSizer> INSTANCE
-
DEFAULT_BLOCK_BUFFER_SIZE
public static final long DEFAULT_BLOCK_BUFFER_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_BUFFER_OUTPUT_STREAM_SIZE
public static final long DEFAULT_BUFFER_OUTPUT_STREAM_SIZE
- See Also:
- Constant Field Values
-
UNKNOWN_SIZE
public static final long UNKNOWN_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBlockSize
public long getBlockSize(Path file) throws IOException
Returns the number of bytes per block in the file store of this file.- Parameters:
file- a non-null file as byte source- Returns:
- a positive value representing the block size in bytes if available, -1 otherwise
- Throws:
IOException- if an I/O error occurs- See Also:
- https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileStore.html#getBlockSize()
-
getBlockSize
public long getBlockSize(InputStream stream) throws IOException
Returns the number of bytes per block in the input stream implementation.- Parameters:
stream- a non-null input stream as byte source- Returns:
- a positive value representing the block size in bytes if available, -1 otherwise
- Throws:
IOException- if an I/O error occurs
-
getBlockSize
public long getBlockSize(OutputStream stream) throws IOException
Returns the number of bytes per block in the output stream implementation.- Parameters:
stream- a non-null output stream as byte source- Returns:
- a positive value representing the block size in bytes if available, -1 otherwise
- Throws:
IOException- if an I/O error occurs
-
-