filebot/source/net/sourceforge/filebot/hash/VerificationFileWriter.java

52 lines
1.1 KiB
Java

package net.sourceforge.filebot.hash;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import net.sourceforge.filebot.Settings;
public class VerificationFileWriter implements Closeable {
protected PrintWriter out;
protected VerificationFormat format;
public VerificationFileWriter(File file, VerificationFormat format, String charset) throws IOException {
this(new PrintWriter(file, charset), format, charset);
}
public VerificationFileWriter(PrintWriter out, VerificationFormat format, String charset) {
this.out = out;
this.format = format;
// start by printing the file header
writeHeader(charset);
}
protected void writeHeader(String charset) {
out.format("; Generated by %s %s on %tF at %<tT%n", Settings.getApplicationName(), Settings.getApplicationVersion(), new Date());
out.format("; charset=%s%n", charset);
out.format(";%n");
}
public void write(String path, String hash) {
out.format("%s%n", format.format(path, hash));
}
@Override
public void close() throws IOException {
out.close();
}
}