Skip to content
Snippets Groups Projects
Commit a33e64a0 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

TokenizerTest uses unencrypted file for comparison

minor error corrections
parent ae776cbb
No related branches found
No related tags found
No related merge requests found
......@@ -9,10 +9,10 @@ public class ByteArray2String extends ConsumerStage<byte[]> {
@Override
protected void execute(final byte[] element) {
this.send(outputPort, new String(element));
this.send(this.outputPort, new String(element));
}
public OutputPort<? extends String> getOutputPort() {
return outputPort;
return this.outputPort;
}
}
......@@ -15,14 +15,14 @@ public class CipherByteArray extends ConsumerStage<byte[]> {
private final OutputPort<byte[]> outputPort = this.createOutputPort();
private Cipher cipher = null;
private final byte[] salt = { 't', 'e', 's', 't' };
private SecretKeySpec skeyspec = null;
public enum CipherMode {
ENCRYPT, DECRYPT
}
public CipherByteArray(final String password, final CipherMode mode) {
final byte[] salt = { 't', 'e', 's', 't' };
SecretKeySpec skeyspec = null;
KeySpec keySpec = new PBEKeySpec(password.toCharArray(),
salt,
......@@ -40,11 +40,11 @@ public class CipherByteArray extends ConsumerStage<byte[]> {
skeyspec = new SecretKeySpec(secretKey.getEncoded(), "AES");
try {
cipher = Cipher.getInstance(skeyspec.getAlgorithm());
this.cipher = Cipher.getInstance(skeyspec.getAlgorithm());
if (mode == CipherMode.ENCRYPT) {
cipher.init(Cipher.ENCRYPT_MODE, skeyspec);
this.cipher.init(Cipher.ENCRYPT_MODE, skeyspec);
} else {
cipher.init(Cipher.DECRYPT_MODE, skeyspec);
this.cipher.init(Cipher.DECRYPT_MODE, skeyspec);
}
} catch (Exception e) {
e.printStackTrace();
......@@ -57,16 +57,16 @@ public class CipherByteArray extends ConsumerStage<byte[]> {
byte[] output = null;
try {
output = cipher.doFinal(element);
output = this.cipher.doFinal(element);
} catch (Exception e) {
e.printStackTrace();
}
this.send(outputPort, output);
this.send(this.outputPort, output);
}
public OutputPort<? extends byte[]> getOutputPort() {
return outputPort;
return this.outputPort;
}
}
......@@ -16,14 +16,14 @@ public class Tokenizer extends ConsumerStage<String> {
@Override
protected void execute(final String element) {
StringTokenizer st = new StringTokenizer(element, regex);
StringTokenizer st = new StringTokenizer(element, this.regex);
while (st.hasMoreTokens()) {
this.send(outputPort, st.nextToken());
this.send(this.outputPort, st.nextToken());
}
}
public OutputPort<? extends String> getOutputPort() {
return outputPort;
return this.outputPort;
}
}
......@@ -40,7 +40,7 @@ public class ZipByteArray extends ConsumerStage<byte[]> {
} catch (Exception e) {
e.printStackTrace();
}
this.send(outputPort, cache);
this.send(this.outputPort, cache);
}
private byte[] compress(final byte[] data) throws IOException {
......@@ -82,7 +82,7 @@ public class ZipByteArray extends ConsumerStage<byte[]> {
}
public OutputPort<? extends byte[]> getOutputPort() {
return outputPort;
return this.outputPort;
}
}
......@@ -17,14 +17,14 @@ public class File2ByteArray extends ConsumerStage<File> implements HeadStage {
protected void execute(final File element) {
try {
byte[] cache = Files.toByteArray(element);
this.send(outputPort, cache);
this.send(this.outputPort, cache);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public OutputPort<? extends byte[]> getOutputPort() {
return outputPort;
return this.outputPort;
}
@Override
......
......@@ -15,20 +15,16 @@ import teetime.stage.io.File2ByteArray;
public class CipherConfiguration extends AnalysisConfiguration {
private final File input, output;
private final String password;
public CipherConfiguration(final String inputFile, final String outputFile, final String password) {
this.input = new File(inputFile);
this.output = new File(outputFile);
this.password = password;
final File input = new File(inputFile);
final File output = new File(outputFile);
InitialElementProducer<File> init = new InitialElementProducer<File>(this.input);
InitialElementProducer<File> init = new InitialElementProducer<File>(input);
File2ByteArray f2b = new File2ByteArray();
CipherByteArray enc = new CipherByteArray(this.password, CipherMode.ENCRYPT);
CipherByteArray enc = new CipherByteArray(password, CipherMode.ENCRYPT);
ZipByteArray comp = new ZipByteArray(ZipMode.COMP);
ZipByteArray decomp = new ZipByteArray(ZipMode.DECOMP);
CipherByteArray decrypt = new CipherByteArray(this.password, CipherMode.DECRYPT);
CipherByteArray decrypt = new CipherByteArray(password, CipherMode.DECRYPT);
ByteArrayFileWriter writer = new ByteArrayFileWriter(output);
PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false)
......
......@@ -17,18 +17,15 @@ import teetime.stage.io.File2ByteArray;
public class TokenizerConfiguration extends AnalysisConfiguration {
private final File input;
private final String password;
private final Counter<String> counter;
public TokenizerConfiguration(final String inputFile, final String password) {
this.input = new File(inputFile);
this.password = password;
final File input = new File(inputFile);
InitialElementProducer<File> init = new InitialElementProducer<File>(this.input);
InitialElementProducer<File> init = new InitialElementProducer<File>(input);
File2ByteArray f2b = new File2ByteArray();
ZipByteArray decomp = new ZipByteArray(ZipMode.DECOMP);
CipherByteArray decrypt = new CipherByteArray(this.password, CipherMode.DECRYPT);
CipherByteArray decrypt = new CipherByteArray(password, CipherMode.DECRYPT);
ByteArray2String b2s = new ByteArray2String();
Tokenizer tokenizer = new Tokenizer(" ");
counter = new Counter<String>();
......
package teetime.examples.tokenizer;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import org.junit.Assert;
import org.junit.Test;
import teetime.framework.Analysis;
import com.google.common.io.Files;
public class TokenizerTest {
@Test
public void executeTest() {
public void executeTest() throws IOException {
// Encrypted lorem ipsum
String inputFile = "src/test/resources/data/cipherInput.txt";
String password = "Password";
......@@ -18,7 +24,9 @@ public class TokenizerTest {
analysis.init();
analysis.start();
Assert.assertEquals(970, configuration.getTokenCount());
String string = Files.toString(new File("src/test/resources/data/input.txt"), Charset.forName("UTF-8"));
Assert.assertEquals(string.split(" ").length, configuration.getTokenCount());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment