individual file hashing works. filetree still fails
This commit is contained in:
parent
2053df7311
commit
5367a00cdc
@ -19,8 +19,6 @@
|
|||||||
package net.szum123321.textile_backup.core.digest;
|
package net.szum123321.textile_backup.core.digest;
|
||||||
|
|
||||||
import net.szum123321.textile_backup.Globals;
|
import net.szum123321.textile_backup.Globals;
|
||||||
import net.szum123321.textile_backup.TextileBackup;
|
|
||||||
import net.szum123321.textile_backup.TextileLogger;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.FilterOutputStream;
|
import java.io.FilterOutputStream;
|
||||||
@ -29,45 +27,31 @@ import java.io.OutputStream;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class HashingOutputStream extends FilterOutputStream {
|
public class HashingOutputStream extends FilterOutputStream {
|
||||||
private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
|
|
||||||
|
|
||||||
private final Path path;
|
private final Path path;
|
||||||
private final Hash hasher = Globals.CHECKSUM_SUPPLIER.get();
|
private final Hash hasher = Globals.CHECKSUM_SUPPLIER.get();
|
||||||
private final FileTreeHashBuilder hashBuilder;
|
private final FileTreeHashBuilder hashBuilder;
|
||||||
|
|
||||||
private long cnt = 0;
|
|
||||||
|
|
||||||
public HashingOutputStream(OutputStream out, Path path, FileTreeHashBuilder hashBuilder) {
|
public HashingOutputStream(OutputStream out, Path path, FileTreeHashBuilder hashBuilder) {
|
||||||
super(out);
|
super(out);
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.hashBuilder = hashBuilder;
|
this.hashBuilder = hashBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() throws IOException {
|
|
||||||
//log.info("Called flush! {}", path);
|
|
||||||
super.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int b) throws IOException {
|
public void write(int b) throws IOException {
|
||||||
hasher.update(b);
|
hasher.update(b);
|
||||||
cnt++;
|
out.write(b);
|
||||||
super.write(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte @NotNull [] b, int off, int len) throws IOException {
|
public void write(byte @NotNull [] b, int off, int len) throws IOException {
|
||||||
cnt += len;
|
|
||||||
log.info("Called: {} with {}", path, len);
|
|
||||||
hasher.update(b, off, len);
|
hasher.update(b, off, len);
|
||||||
super.write(b, off, len);
|
out.write(b, off, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
long h = hasher.getValue();
|
long h = hasher.getValue();
|
||||||
log.info("Read in: {}, of {}, with hash {}", path, cnt, h);
|
|
||||||
hashBuilder.update(path, h);
|
hashBuilder.update(path, h);
|
||||||
super.close();
|
super.close();
|
||||||
|
|
||||||
|
@ -47,10 +47,6 @@ public class ZipDecompressor {
|
|||||||
ZipArchiveEntry entry = it.next();
|
ZipArchiveEntry entry = it.next();
|
||||||
Path file = target.resolve(entry.getName());
|
Path file = target.resolve(entry.getName());
|
||||||
|
|
||||||
byte[] buff = new byte[4096];
|
|
||||||
|
|
||||||
log.info("Unpacking {} uncompressed {} compressed {}", entry.getName(), entry.getSize(), entry.getCompressedSize());
|
|
||||||
|
|
||||||
if(entry.isDirectory()) {
|
if(entry.isDirectory()) {
|
||||||
Files.createDirectories(file);
|
Files.createDirectories(file);
|
||||||
} else {
|
} else {
|
||||||
@ -59,15 +55,7 @@ public class ZipDecompressor {
|
|||||||
HashingOutputStream out = new HashingOutputStream(outputStream, file, hashBuilder);
|
HashingOutputStream out = new HashingOutputStream(outputStream, file, hashBuilder);
|
||||||
InputStream in = zipFile.getInputStream(entry)) {
|
InputStream in = zipFile.getInputStream(entry)) {
|
||||||
|
|
||||||
int n;
|
IOUtils.copy(in, out);
|
||||||
long count = 0;
|
|
||||||
while((n = in.read(buff, 0, buff.length)) >= 1) {
|
|
||||||
out.write(buff, 0, n);
|
|
||||||
count += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("File {}, in size {}, copied {}", entry.getName(), in.available(), count);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user