Commit d8f38215 by Facundo Javier Gelatti

Reorganize classes and packages

1 parent 95ddd54c
Showing 20 changed files with 173 additions and 149 deletions
package org.stegosuite.ui.gui;
package org.stegosuite.application;
import java.util.Observable;
import java.util.Observer;
......
package org.stegosuite.ui.gui;
package org.stegosuite.application;
import org.eclipse.swt.graphics.ImageData;
import org.stegosuite.application.block_processing.BlockProcessor;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.embedding.EmbeddingProgress;
import org.stegosuite.image.embedding.Visualizer;
......@@ -9,26 +10,18 @@ import org.stegosuite.model.exception.SteganoEmbedException;
import org.stegosuite.model.exception.SteganoExtractException;
import org.stegosuite.model.exception.SteganoImageException;
import org.stegosuite.model.payload.Payload;
import org.stegosuite.model.payload.block.Block;
import org.stegosuite.model.payload.block.FileBlock;
import org.stegosuite.model.payload.block.MessageBlock;
import org.stegosuite.ui.gui.embedding.Embedding;
import org.stegosuite.ui.gui.embedding.EmbeddingDoneListener;
import org.stegosuite.ui.gui.embedding.EmbeddingFactory;
import org.stegosuite.ui.gui.embedding.ExtractingDoneListener;
import org.stegosuite.application.embedding.Embedding;
import org.stegosuite.application.embedding.EmbeddingDoneListener;
import org.stegosuite.application.embedding.EmbeddingFactory;
import org.stegosuite.application.embedding.ExtractingDoneListener;
import org.stegosuite.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static java.nio.file.StandardOpenOption.CREATE;
public class StegosuitePresenter implements EmbeddingDoneListener, ExtractingDoneListener {
private ImageFormat image;
private Payload payload;
......@@ -167,123 +160,4 @@ public class StegosuitePresenter implements EmbeddingDoneListener, ExtractingDon
return embedding.getCapacity();
}
private static class BlockProcessor {
private final Payload payload;
private final List<String> messages = new ArrayList<>();
private final List<String> filePaths = new ArrayList<>();
private final String baseFilePath;
public BlockProcessor(Payload payload, String baseFilePath) {
this.baseFilePath = baseFilePath;
this.payload = payload;
}
public BlockProcessor processBlocks() {
payload.getBlocks().stream()
.map(block -> toBlockContainer(block))
.forEach(BlockContainer::processBlock);
return this;
}
private BlockContainer toBlockContainer(Block aBlock) {
switch (aBlock.getIdentifier()) {
case FileBlock.IDENTIFIER:
return new FileBlockContainer((FileBlock) aBlock, filePaths, baseFilePath);
case MessageBlock.IDENTIFIER:
return new MessageBlockContainer((MessageBlock) aBlock, messages);
default:
return null;
}
}
public List<String> getFilePaths() {
return filePaths;
}
public String getExtractedMessage() {
return messages.get(0);
}
public String getStatusText() {
String status = "Extracting completed.";
if (thereWereProcessedFiles()) {
status += " Extracted file saved to " + lastFilePath();
}
return status;
}
private boolean thereWereProcessedFiles() {
return !filePaths.isEmpty();
}
private String lastFilePath() {
return filePaths.get(filePaths.size() - 1);
}
static class FileBlockContainer implements BlockContainer {
private final FileBlock block;
private final List<String> processedFiles;
private final String baseFilePath;
public FileBlockContainer(FileBlock block, List<String> processedFiles, String baseFilePath) {
this.block = block;
this.processedFiles = processedFiles;
this.baseFilePath = baseFilePath;
}
@Override
public void processBlock() {
String extractionPath = getExtractionPath();
saveFileTo(extractionPath);
markAsProcessed(extractionPath);
}
private String getExtractionPath() {
return FileUtils.changeFileName(
baseFilePath,
block.getFileName()
);
}
private void saveFileTo(String extractionPath) {
try {
writeContentToFileIn(extractionPath);
} catch (IOException e) {
e.printStackTrace();
}
}
private void writeContentToFileIn(String extractionPath) throws IOException {
byte[] fileContent = block.getFileContent();
Path path = Paths.get(extractionPath);
Files.write(path, fileContent, CREATE);
}
private void markAsProcessed(String extractionPath) {
processedFiles.add(extractionPath);
}
}
static class MessageBlockContainer implements BlockContainer {
private MessageBlock block;
private List<String> processedMessages;
public MessageBlockContainer(MessageBlock block, List<String> messages) {
this.block = block;
this.processedMessages = messages;
}
@Override
public void processBlock() {
String message = block.getMessage();
processedMessages.add(message);
}
}
}
interface BlockContainer {
void processBlock();
}
}
package org.stegosuite.ui.gui;
package org.stegosuite.application;
import org.eclipse.swt.graphics.ImageData;
import org.stegosuite.image.embedding.Visualizer;
......
package org.stegosuite.application.block_processing;
interface BlockContainer {
void processBlock();
}
package org.stegosuite.application.block_processing;
import org.stegosuite.model.payload.Payload;
import org.stegosuite.model.payload.block.Block;
import org.stegosuite.model.payload.block.FileBlock;
import org.stegosuite.model.payload.block.MessageBlock;
import java.util.ArrayList;
import java.util.List;
public class BlockProcessor {
private final Payload payload;
private final List<String> messages = new ArrayList<>();
private final List<String> filePaths = new ArrayList<>();
private final String baseFilePath;
public BlockProcessor(Payload payload, String baseFilePath) {
this.baseFilePath = baseFilePath;
this.payload = payload;
}
public BlockProcessor processBlocks() {
payload.getBlocks().stream()
.map(block -> toBlockContainer(block))
.forEach(BlockContainer::processBlock);
return this;
}
private BlockContainer toBlockContainer(Block aBlock) {
switch (aBlock.getIdentifier()) {
case FileBlock.IDENTIFIER:
return new FileBlockContainer((FileBlock) aBlock, filePaths, baseFilePath);
case MessageBlock.IDENTIFIER:
return new MessageBlockContainer((MessageBlock) aBlock, messages);
default:
return null;
}
}
public List<String> getFilePaths() {
return filePaths;
}
public String getExtractedMessage() {
return messages.get(0);
}
public String getStatusText() {
String status = "Extracting completed.";
if (thereWereProcessedFiles()) {
status += " Extracted file saved to " + lastFilePath();
}
return status;
}
private boolean thereWereProcessedFiles() {
return !filePaths.isEmpty();
}
private String lastFilePath() {
return filePaths.get(filePaths.size() - 1);
}
}
package org.stegosuite.application.block_processing;
import org.stegosuite.model.payload.block.FileBlock;
import org.stegosuite.util.FileUtils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static java.nio.file.StandardOpenOption.CREATE;
class FileBlockContainer implements BlockContainer {
private final FileBlock block;
private final List<String> processedFiles;
private final String baseFilePath;
public FileBlockContainer(FileBlock block, List<String> processedFiles, String baseFilePath) {
this.block = block;
this.processedFiles = processedFiles;
this.baseFilePath = baseFilePath;
}
@Override
public void processBlock() {
String extractionPath = getExtractionPath();
saveFileTo(extractionPath);
markAsProcessed(extractionPath);
}
private String getExtractionPath() {
return FileUtils.changeFileName(
baseFilePath,
block.getFileName()
);
}
private void saveFileTo(String extractionPath) {
try {
writeContentToFileIn(extractionPath);
} catch (IOException e) {
e.printStackTrace();
}
}
private void writeContentToFileIn(String extractionPath) throws IOException {
byte[] fileContent = block.getFileContent();
Path path = Paths.get(extractionPath);
Files.write(path, fileContent, CREATE);
}
private void markAsProcessed(String extractionPath) {
processedFiles.add(extractionPath);
}
}
package org.stegosuite.application.block_processing;
import org.stegosuite.model.payload.block.MessageBlock;
import java.util.List;
class MessageBlockContainer implements BlockContainer {
private MessageBlock block;
private List<String> processedMessages;
public MessageBlockContainer(MessageBlock block, List<String> messages) {
this.block = block;
this.processedMessages = messages;
}
@Override
public void processBlock() {
String message = block.getMessage();
processedMessages.add(message);
}
}
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingProgress;
import org.stegosuite.model.exception.SteganoEmbedException;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.format.ImageFormat;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.format.ImageFormat;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.embedding.EmbeddingProgress;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.embedding.EmbeddingProgress;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.embedding.EmbeddingProgress;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.embedding.EmbeddingProgress;
......
package org.stegosuite.ui.gui.embedding;
package org.stegosuite.application.embedding;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.embedding.EmbeddingProgress;
......
......@@ -17,8 +17,8 @@ import org.stegosuite.model.payload.Payload;
import org.stegosuite.model.payload.block.Block;
import org.stegosuite.model.payload.block.FileBlock;
import org.stegosuite.model.payload.block.MessageBlock;
import org.stegosuite.ui.gui.embedding.Embedding;
import org.stegosuite.ui.gui.embedding.EmbeddingFactory;
import org.stegosuite.application.embedding.Embedding;
import org.stegosuite.application.embedding.EmbeddingFactory;
import org.stegosuite.util.FileUtils;
public class Cli {
......
......@@ -35,6 +35,9 @@ import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stegosuite.application.EmbeddingProgressObserver;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import org.stegosuite.image.embedding.EmbeddingProgress;
import org.stegosuite.image.embedding.Visualizer;
import org.stegosuite.image.format.ImageFormat;
......
......@@ -10,8 +10,8 @@ import org.stegosuite.model.exception.SteganoEmbedException;
import org.stegosuite.model.exception.SteganoExtractException;
import org.stegosuite.model.exception.SteganoImageException;
import org.stegosuite.model.exception.SteganoKeyException;
import org.stegosuite.ui.gui.StegosuitePresenter;
import org.stegosuite.ui.gui.StegosuiteUI;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import java.io.File;
......
......@@ -10,8 +10,8 @@ import org.stegosuite.image.format.ImageFormat;
import org.stegosuite.model.exception.SteganoEmbedException;
import org.stegosuite.model.exception.SteganoExtractException;
import org.stegosuite.model.exception.SteganoImageException;
import org.stegosuite.ui.gui.StegosuitePresenter;
import org.stegosuite.ui.gui.StegosuiteUI;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import java.io.File;
import java.io.IOException;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!