1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-14 13:25:10 -05:00
filebot/source/net/filebot/hash/VerificationFileWriter.java
2014-04-19 06:30:29 +00:00

52 lines
1.1 KiB
Java

package net.filebot.hash;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import net.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();
}
}