Class NioFileCopierWithProgressMeter
java.lang.Object
org.broadinstitute.hellbender.utils.nio.NioFileCopierWithProgressMeter
Class to copy a file using
java.nio
.
Operates using paths.
INSTANCES OF THIS CLASS ARE NOT THREAD-SAFE!
Created by jonn on 8/27/18.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An interface that defines a method to use to calculate a checksum on anInputStream
.static enum
An enum to allow for verbosity of logging progress of anNioFileCopierWithProgressMeter
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
protected String
protected static final int
protected final byte[]
protected boolean
protected static final long
protected static final double
protected final Path
protected String
protected boolean
protected static final long
protected static final int
protected long
protected double
protected MessageDigest
protected static final long
protected static final int
protected static final int
protected static final int
protected static final boolean
protected boolean
protected long
protected double
protected static final long
protected final Path
protected long
protected int
protected long
protected NioFileCopierWithProgressMeter.Verbosity
protected static final NioFileCopierWithProgressMeter.Verbosity
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
NioFileCopierWithProgressMeter
(Path source, Path dest, boolean overwriteExisting, NioFileCopierWithProgressMeter.Verbosity verbosity) NioFileCopierWithProgressMeter
uses a factory pattern. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Create anNioFileCopierWithProgressMeter
.Create anNioFileCopierWithProgressMeter
.create
(Path source, Path dest, boolean overwriteExisting, NioFileCopierWithProgressMeter.Verbosity verbosity) Create anNioFileCopierWithProgressMeter
.protected void
determineProgessDisplayIncrement
(long fileSize) protected void
doCopy()
protected String
formatMillisecondsTime
(long time_ms) getDest()
protected Duration
getRemainingDuration
(long totalBytesRead, double bytesPerMillisecond) boolean
boolean
protected boolean
isSilent()
protected void
logProgress
(double progressValue, long totalBytesRead, double bytesPerMillisecond) protected void
logProgressSimple
(double progressValue, long totalBytesRead, double bytesPerMillisecond) protected void
logProgressVerbose
(double progressValue, long totalBytesRead, double bytesPerMillisecond) setChecksumAlgorithmAndExpectedChecksum
(String algorithm, String expectedChecksum) Sets themessageDigest
and expected checksum to be used by thisNioFileCopierWithProgressMeter
to validate the copied file.Sets the logger to log the time remaining in timestamp format ala 'DD:HH:MM:ss.SS'.Sets the logger to log the time remaining in word format ala 'D days, H hours, M minutes, s seconds'.setOverwriteExisting
(boolean overwriteExisting) Sets whether thisNioFileCopierWithProgressMeter
will overwritedest
when copying.Sets the progress meterverbosity
of thisNioFileCopierWithProgressMeter
.protected void
updateCopyProgress
(int bytesRead) protected void
updateMessageDigest
(byte[] copyBuffer, int startIndex, int endIndex)
-
Field Details
-
BUFFER_SIZE_BYTES
protected static final int BUFFER_SIZE_BYTES- See Also:
-
DEFAULT_PROGRESS_DISPLAY_PERCENT_INCREMENT
protected static final double DEFAULT_PROGRESS_DISPLAY_PERCENT_INCREMENT- See Also:
-
SECOND_IN_MS
protected static final long SECOND_IN_MS- See Also:
-
MINUTE_IN_MS
protected static final long MINUTE_IN_MS- See Also:
-
HOUR_IN_MS
protected static final long HOUR_IN_MS- See Also:
-
DAY_IN_MS
protected static final long DAY_IN_MS- See Also:
-
KB_TO_BYTES
protected static final int KB_TO_BYTES- See Also:
-
MS_TO_SEC
protected static final int MS_TO_SEC- See Also:
-
NANOS_TO_MILLIS
protected static final int NANOS_TO_MILLIS- See Also:
-
NANOS_TO_SECONDS
protected static final int NANOS_TO_SECONDS- See Also:
-
COPY_SPEED_HISTORY_SIZE
protected static final int COPY_SPEED_HISTORY_SIZE- See Also:
-
OVERWRITE_EXISTING_DEFAULT
protected static final boolean OVERWRITE_EXISTING_DEFAULT- See Also:
-
VERBOSITY_DEFAULT
-
source
-
dest
-
srcFileSize
protected long srcFileSize -
srcFileSizeNumDigits
protected int srcFileSizeNumDigits -
checksum
-
messageDigest
-
expectedChecksum
-
overwriteExisting
protected boolean overwriteExisting -
verbosity
-
formatTimeRemainingAsTimestamp
protected boolean formatTimeRemainingAsTimestamp -
copyBuffer
protected final byte[] copyBuffer -
progressPercentDisplayIncrement
protected double progressPercentDisplayIncrement -
downloadBytesPerMilliSecond
-
copyComplete
protected boolean copyComplete -
totalBytesRead
protected long totalBytesRead -
progressBytesRead
protected long progressBytesRead -
lastProgressValue
protected double lastProgressValue -
lastProgressTime_ns
protected long lastProgressTime_ns
-
-
Constructor Details
-
NioFileCopierWithProgressMeter
protected NioFileCopierWithProgressMeter(Path source, Path dest, boolean overwriteExisting, NioFileCopierWithProgressMeter.Verbosity verbosity) NioFileCopierWithProgressMeter
uses a factory pattern. This internal constructor is to be used by the class itself.- Parameters:
source
- ThePath
to the source file for the copy.dest
- ThePath
to the destination file for the copy.overwriteExisting
- Iftrue
will overwrite an existing file in the location specified bydest
.verbosity
-NioFileCopierWithProgressMeter.Verbosity
of the progress progress log over the duration of the copy.
-
-
Method Details
-
create
Create anNioFileCopierWithProgressMeter
. By default the resultingNioFileCopierWithProgressMeter
will not overwrite the destination if anything already exists there.- Parameters:
source
- ThePath
to the source file for the copy.dest
- ThePath
to the destination file for the copy.- Returns:
- An
NioFileCopierWithProgressMeter
initialized to copy the file located atsource
to the location specified bydest
.
-
create
public static NioFileCopierWithProgressMeter create(Path source, Path dest, boolean overwriteExisting) Create anNioFileCopierWithProgressMeter
. Will periodically display progress of copying files.- Parameters:
source
- ThePath
to the source file for the copy.dest
- ThePath
to the destination file for the copy.overwriteExisting
- Iftrue
will overwrite an existing file in the location specified bydest
.- Returns:
- An
NioFileCopierWithProgressMeter
initialized to copy the file located atsource
to the location specified bydest
.
-
create
public static NioFileCopierWithProgressMeter create(Path source, Path dest, boolean overwriteExisting, NioFileCopierWithProgressMeter.Verbosity verbosity) Create anNioFileCopierWithProgressMeter
.- Parameters:
source
- ThePath
to the source file for the copy.dest
- ThePath
to the destination file for the copy.overwriteExisting
- Iftrue
will overwrite an existing file in the location specified bydest
.verbosity
-NioFileCopierWithProgressMeter.Verbosity
of the progress progress log over the duration of the copy.- Returns:
- An
NioFileCopierWithProgressMeter
initialized to copy the file located atsource
to the location specified bydest
.
-
getSource
- Returns:
- A copy of the
Path
used as the source for thisNioFileCopierWithProgressMeter
.
-
getDest
- Returns:
- A copy of the
Path
used as the destination for thisNioFileCopierWithProgressMeter
.
-
isCopyComplete
public boolean isCopyComplete()- Returns:
true
iff thesource
has been copied to thedest
in thisNioFileCopierWithProgressMeter
.false
otherwise.
-
isOverwriteExisting
public boolean isOverwriteExisting()- Returns:
true
iff thisNioFileCopierWithProgressMeter
will overwritedest
when copying.false
otherwise.
-
setOverwriteExisting
Sets whether thisNioFileCopierWithProgressMeter
will overwritedest
when copying. -
setChecksumAlgorithmAndExpectedChecksum
public NioFileCopierWithProgressMeter setChecksumAlgorithmAndExpectedChecksum(String algorithm, String expectedChecksum) Sets themessageDigest
and expected checksum to be used by thisNioFileCopierWithProgressMeter
to validate the copied file. NOTE: Setting these values will automatically cause the file to be checked for integrity upon copy completion.- Parameters:
algorithm
-String
specifying the checksum algorithm to be used to calculate the checksum of the copied file.expectedChecksum
- Expected value of the checksum calculated by the givenmessageDigest
for the copied file.
-
setFormatTimeRemainingAsTimestamp
Sets the logger to log the time remaining in timestamp format ala 'DD:HH:MM:ss.SS'. -
setFormatTimeRemainingAsWords
Sets the logger to log the time remaining in word format ala 'D days, H hours, M minutes, s seconds'. -
getVerbosity
- Returns:
- The
NioFileCopierWithProgressMeter.Verbosity
at which thisNioFileCopierWithProgressMeter
will log copy progress.
-
setVerbosity
public NioFileCopierWithProgressMeter setVerbosity(NioFileCopierWithProgressMeter.Verbosity verbosity) Sets the progress meterverbosity
of thisNioFileCopierWithProgressMeter
. -
updateMessageDigest
protected void updateMessageDigest(byte[] copyBuffer, int startIndex, int endIndex) -
calculateChecksumFromMessageDigest
protected void calculateChecksumFromMessageDigest() -
isSilent
protected boolean isSilent() -
formatMillisecondsTime
-
logProgress
protected void logProgress(double progressValue, long totalBytesRead, double bytesPerMillisecond) -
getRemainingDuration
-
logProgressSimple
protected void logProgressSimple(double progressValue, long totalBytesRead, double bytesPerMillisecond) -
logProgressVerbose
protected void logProgressVerbose(double progressValue, long totalBytesRead, double bytesPerMillisecond) -
updateCopyProgress
protected void updateCopyProgress(int bytesRead) -
determineProgessDisplayIncrement
protected void determineProgessDisplayIncrement(long fileSize) -
doCopy
protected void doCopy() -
initiateCopy
-