Skip to content
Permalink
Browse files
Removed Guava from dependencies.
git-svn-id: https://svn.apache.org/repos/asf/james/mime4j/trunk@1351620 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ieugen committed Jun 19, 2012
1 parent 9c3b4c5 commit 16eb70ffdfcccd7321eba573ab2c18dabfc42834
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
@@ -3,3 +3,5 @@
.settings
target
maven-eclipse.xml
.idea/
*.iml
@@ -18,7 +18,6 @@
****************************************************************/
package org.apache.james.mime4j.samples.mbox;

import com.google.common.base.Charsets;
import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.dom.Message;
import org.apache.james.mime4j.dom.MessageBuilder;
@@ -33,6 +32,7 @@
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

/**
@@ -41,7 +41,7 @@
*/
public class IterateOverMbox {

private final static CharsetEncoder ENCODER = Charsets.UTF_8.newEncoder();
private final static CharsetEncoder ENCODER = Charset.forName("UTF-8").newEncoder();

// simple example of how to split an mbox into individual files
public static void main(String[] args) throws Exception {
@@ -53,9 +53,9 @@ public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();
int count = 0;

for (CharBufferWrapper message : MboxIterator.fromFile(mbox).charset(Charsets.UTF_8).build()) {
for (CharBufferWrapper message : MboxIterator.fromFile(mbox).charset(ENCODER.charset()).build()) {
// saveMessageToFile(count, buf);
System.out.println(messageSummary(message.asInputStreamUTF8Encoded()));
System.out.println(messageSummary(message.asInputStream(ENCODER.charset())));
count++;
}
System.out.println("Found " + count + " messages");
@@ -72,6 +72,14 @@ private static void saveMessageToFile(int count, CharBuffer buf) throws IOExcept
fout.close();
}

/**
* Parse a message and return a simple {@link String} representation of some important fields.
*
* @param messageBytes the message as {@link java.io.InputStream}
* @return String
* @throws IOException
* @throws MimeException
*/
private static String messageSummary(InputStream messageBytes) throws IOException, MimeException {
MessageBuilder builder = new DefaultMessageBuilder();
Message message = builder.parseMessage(messageBytes);
@@ -44,10 +44,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>

</project>
@@ -18,9 +18,6 @@
****************************************************************/
package org.apache.james.mime4j.mboxiterator;

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -35,14 +32,12 @@ public class CharBufferWrapper {
private final CharBuffer messageBuffer;

public CharBufferWrapper(CharBuffer messageBuffer) {
Preconditions.checkNotNull(messageBuffer);
if (messageBuffer == null) {
throw new IllegalStateException("The buffer is null");
}
this.messageBuffer = messageBuffer;
}

public InputStream asInputStreamUTF8Encoded() {
return new ByteBufferInputStream(Charsets.UTF_8.encode(messageBuffer));
}

public InputStream asInputStream(Charset encoding) {
return new ByteBufferInputStream(encoding.encode(messageBuffer));
}
@@ -18,8 +18,6 @@
****************************************************************/
package org.apache.james.mime4j.mboxiterator;

import com.google.common.base.Charsets;

import java.io.*;
import java.nio.Buffer;
import java.nio.CharBuffer;
@@ -207,7 +205,7 @@ public static Builder fromFile(String file) {
public static class Builder {

private final File file;
private Charset charset = Charsets.UTF_8;
private Charset charset = Charset.forName("UTF-8");
private String regexpPattern = FromLinePatterns.DEFAULT;
private int flags = Pattern.MULTILINE;
/**
@@ -18,21 +18,15 @@
****************************************************************/
package org.apache.james.mime4j.mboxiterator;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;

/**
* Tests for {@link MboxIterator}.
*
* @author estan
*/
public class MboxIteratorTest {

@@ -68,11 +62,23 @@ public void testIteratorLoop() throws FileNotFoundException, IOException {
private void iterateWithMaxMessage(int maxMessageSize) throws IOException {
int count = 0;
for (CharBufferWrapper msg : MboxIterator.fromFile(MBOX_PATH).maxMessageSize(maxMessageSize).build()) {
String message = Files.toString(new File(MBOX_PATH + "-" + count), Charsets.UTF_8);
String message = fileToString(new File(MBOX_PATH + "-" + count));
//MboxIterator.printCharBuffer(msg);
Assert.assertEquals("String sizes match for file " + count, message.length(), msg.toString().length());
Assert.assertEquals("Missmatch with file " + count, message, msg.toString());
count++;
}
}

private static String fileToString(File file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
int ch;
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
reader.close();
return sb.toString();
}

}
@@ -95,11 +95,6 @@
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
</dependency>
</dependencies>
</dependencyManagement>

0 comments on commit 16eb70f

Please sign in to comment.