Commit 2a6459a0 by Tobias

fix nullpointer exception for embeddings without text message

1 parent 21c97f23
......@@ -46,15 +46,14 @@ public class StegosuitePresenter implements EmbeddingDoneListener, ExtractingDon
return embedding;
}
public void embedNotifying(EmbeddingProgress progressListener, String message, String password) {
public void embedNotifying(EmbeddingProgress progressListener, String password) {
this.progressListener = progressListener;
embed(message, password);
embed(password);
}
public void embed(String message, String password) {
public void embed(String password) {
try {
addMessageToPayload(message);
setPassword(password);
embedData();
} catch (SteganoEmbedException e) {
......@@ -62,7 +61,7 @@ public class StegosuitePresenter implements EmbeddingDoneListener, ExtractingDon
}
}
private void addMessageToPayload(String message) {
public void addMessageToPayload(String message) {
payload.addBlock(new MessageBlock(message));
}
......
......@@ -39,8 +39,12 @@ public class Cli
return;
pointFilter(cmd);
String message = cmd.getOptionValue("m");
if (message != null) {
presenter.addMessageToPayload(message);
}
String[] files = cmd.getOptionValues("f");
if (files != null) {
for (String string : files) {
......@@ -50,11 +54,11 @@ public class Cli
String key = cmd.getOptionValue("k");
embed(message, key);
embed(key);
}
private void embed(String message, String key) {
presenter.embed(message, key);
private void embed(String key) {
presenter.embed(key);
}
public void extract(CommandLine cmd) {
......@@ -121,7 +125,7 @@ public class Cli
@Override
public void showEmbeddingError(SteganoEmbedException e) {
e.printStackTrace();
LOG.info(e.getMessage());
}
@Override
......
......@@ -172,8 +172,10 @@ public class EmbedUi implements StegosuiteUI {
String message = messageField.getText();
String password = getEnteredPassword();
presenter.addMessageToPayload(message);
runInNewThread(() -> presenter.embedNotifying(progress, message, password));
runInNewThread(() -> presenter.embedNotifying(progress, password));
}
private void startExtraction(Composite compositeControls) {
......
......@@ -84,7 +84,8 @@ public class EmbeddingAndExtractingTest {
private void embedPayload(String imageName, String password, String message) throws SteganoImageException, SteganoEmbedException {
String imagePath = pathOf(imageName);
StegosuitePresenter presenter = getPresenterFor(imagePath);
presenter.embedNotifying(new EmbeddingProgress(), message, password);
presenter.addMessageToPayload(message);
presenter.embedNotifying(new EmbeddingProgress(), password);
}
private void extractPayload(String imagePath, String password) throws SteganoImageException, SteganoExtractException {
......
......@@ -64,7 +64,8 @@ public class PresenterTest implements StegosuiteUI, Observer {
@Test
public void embeddingTest() throws Exception {
presenter = presenterWithImage(IMAGE_NAME);
presenter.embedNotifying(progressListener, message, password);
presenter.addMessageToPayload(message);
presenter.embedNotifying(progressListener, password);
assertEquals(100, currentProgress);
assertNotNull(outputVisualizer);
......@@ -76,7 +77,8 @@ public class PresenterTest implements StegosuiteUI, Observer {
@Test
public void extractTest() throws Exception {
presenter = presenterWithImage(IMAGE_NAME);
presenter.embedNotifying(progressListener, message, password);
presenter.addMessageToPayload(message);
presenter.embedNotifying(progressListener, password);
resetCurrentProgress();
presenter = presenterWithImage(EMBEDDED_IMAGE);
......@@ -92,7 +94,8 @@ public class PresenterTest implements StegosuiteUI, Observer {
public void extractFileTest() throws Exception {
presenter = presenterWithImage(IMAGE_NAME);
presenter.addFileToPayload(pathOf(FILE_NAME));
presenter.embedNotifying(progressListener, message, password);
presenter.addMessageToPayload(message);
presenter.embedNotifying(progressListener, password);
resetCurrentProgress();
presenter = presenterWithImage(EMBEDDED_IMAGE);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!