Commit 0667a84d by Facundo Javier Gelatti

Update path in file block when extracting, so that the file size is computed correctly

1 parent d8f38215
......@@ -39,6 +39,7 @@ class FileBlockContainer implements BlockContainer {
private void saveFileTo(String extractionPath) {
try {
writeContentToFileIn(extractionPath);
updateFileNameInBlock(extractionPath);
} catch (IOException e) {
e.printStackTrace();
}
......@@ -50,6 +51,11 @@ class FileBlockContainer implements BlockContainer {
Files.write(path, fileContent, CREATE);
}
private void updateFileNameInBlock(String extractionPath) {
// Update the filename, so that we can compute the file size later
block.setFileName(extractionPath);
}
private void markAsProcessed(String extractionPath) {
processedFiles.add(extractionPath);
}
......
......@@ -9,6 +9,7 @@ import java.nio.file.Paths;
import java.util.Arrays;
import org.stegosuite.util.ByteUtils;
import org.stegosuite.util.FileUtils;
/**
* This block contains the contents of a file as well as its file name
......@@ -74,11 +75,15 @@ public final class FileBlock
}
public long getSize() {
return new File(getFileName()).length();
return FileUtils.getFileSize(fileName);
}
public boolean hasPath(String filename) {
String blockFilename = Paths.get(getFileName()).getFileName().toString();
String blockFilename = Paths.get(fileName).getFileName().toString();
return filename.equals(blockFilename);
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
}
......@@ -12,6 +12,7 @@ import org.stegosuite.model.exception.SteganoExtractException;
import org.stegosuite.model.exception.SteganoImageException;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import org.stegosuite.model.payload.block.FileBlock;
import java.io.File;
import java.io.IOException;
......@@ -103,10 +104,21 @@ public class PresenterTest implements StegosuiteUI, Observer {
assertArrayEquals(imageDataOf(EMBEDDED_IMAGE).data, imageData.data);
assertEquals(FILE_NAME, addedFileName);
assertEquals(FILE_EXTENSION, addedFileExtension);
assertEquals(FILE_CONTENT.length(), fileBlockSize());
assertEquals(FILE_CONTENT.length(), addedFileSize);
assertEquals(FILE_CONTENT, readContentFromFile(FILE_NAME));
}
private long fileBlockSize() {
return presenter.payloadFileBlocksWithFilename(FILE_NAME).stream()
.findFirst().get().getSize();
}
private FileBlock getFileBlockFromPresenter() {
return presenter.payloadFileBlocksWithFilename(FILE_NAME)
.stream().findAny().get();
}
private StegosuitePresenter presenterWithImage(String imageName) throws SteganoImageException {
ImageFormat image = getImage(imageName);
return new StegosuitePresenter(image, this);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!