
com.github.nicosensei.textbatch.job.ByteSizeJobProgress Maven / Gradle / Ivy
/**
*
*/
package com.github.nicosensei.textbatch.job;
import java.io.File;
import java.io.UnsupportedEncodingException;
import com.github.nicosensei.textbatch.Tool;
import com.github.nicosensei.commons.exceptions.Unexpected;
import com.github.nicosensei.commons.utils.datatype.ByteCountFormatter;
/**
* @author ngiraud
*
*/
public class ByteSizeJobProgress extends AbstractJobProgress {
private final static String fileEncoding = Tool.getInstance().getProperty(
InputFileReader.class, "encoding");
private final static int EOL_BYTES;
static {
try {
EOL_BYTES = "\n".getBytes(fileEncoding).length;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
public ByteSizeJobProgress(final String inputFilePath) {
super(new File(inputFilePath).length());
}
@Override
public void notifyLineProcessed(InputLine line) {
try {
// Also add the newline size (not brought back by the reader)
incrementUnitsProcessed(line.getLine().getBytes(fileEncoding).length + EOL_BYTES);
} catch (UnsupportedEncodingException e) {
throw new Unexpected(e);
}
}
@Override
public void logStatus() {
Tool.getInstance().logInfo(
ByteCountFormatter.humanReadableByteCount(getUnitsProcessed())
+ "/"
+ ByteCountFormatter.humanReadableByteCount(getUnitsToProcess())
+ " processed ("
+ PERCENTAGE.format(getCompletionPercentage()) + "%).");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy