james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieu...@apache.org
Subject svn commit: r1351620 - in /james/mime4j/trunk: ./ examples/src/main/java/org/apache/james/mime4j/samples/mbox/ mbox/ mbox/src/main/java/org/apache/james/mime4j/mboxiterator/ mbox/src/test/java/org/apache/james/mime4j/mboxiterator/
Date Tue, 19 Jun 2012 09:41:33 GMT
Author: ieugen
Date: Tue Jun 19 09:41:33 2012
New Revision: 1351620

URL: http://svn.apache.org/viewvc?rev=1351620&view=rev
Log:
Removed Guava from dependencies.

Modified:
    james/mime4j/trunk/.gitignore
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/mbox/IterateOverMbox.java
    james/mime4j/trunk/mbox/pom.xml
    james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/CharBufferWrapper.java
    james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/MboxIterator.java
    james/mime4j/trunk/mbox/src/test/java/org/apache/james/mime4j/mboxiterator/MboxIteratorTest.java
    james/mime4j/trunk/pom.xml

Modified: james/mime4j/trunk/.gitignore
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/.gitignore?rev=1351620&r1=1351619&r2=1351620&view=diff
==============================================================================
--- james/mime4j/trunk/.gitignore (original)
+++ james/mime4j/trunk/.gitignore Tue Jun 19 09:41:33 2012
@@ -3,3 +3,5 @@
 .settings
 target
 maven-eclipse.xml
+.idea/
+*.iml
\ No newline at end of file

Modified: james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/mbox/IterateOverMbox.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/mbox/IterateOverMbox.java?rev=1351620&r1=1351619&r2=1351620&view=diff
==============================================================================
--- james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/mbox/IterateOverMbox.java
(original)
+++ james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/mbox/IterateOverMbox.java
Tue Jun 19 09:41:33 2012
@@ -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.io.InputStream;
 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 @@ import java.nio.charset.CharsetEncoder;
  */
 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 class IterateOverMbox {
         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 @@ public class IterateOverMbox {
         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);

Modified: james/mime4j/trunk/mbox/pom.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/mbox/pom.xml?rev=1351620&r1=1351619&r2=1351620&view=diff
==============================================================================
--- james/mime4j/trunk/mbox/pom.xml (original)
+++ james/mime4j/trunk/mbox/pom.xml Tue Jun 19 09:41:33 2012
@@ -44,10 +44,6 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-        </dependency>
     </dependencies>
 
 </project>

Modified: james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/CharBufferWrapper.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/CharBufferWrapper.java?rev=1351620&r1=1351619&r2=1351620&view=diff
==============================================================================
--- james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/CharBufferWrapper.java
(original)
+++ james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/CharBufferWrapper.java
Tue Jun 19 09:41:33 2012
@@ -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));
     }

Modified: james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/MboxIterator.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/MboxIterator.java?rev=1351620&r1=1351619&r2=1351620&view=diff
==============================================================================
--- james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/MboxIterator.java
(original)
+++ james/mime4j/trunk/mbox/src/main/java/org/apache/james/mime4j/mboxiterator/MboxIterator.java
Tue Jun 19 09:41:33 2012
@@ -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 class MboxIterator implements Ite
     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;
         /**

Modified: james/mime4j/trunk/mbox/src/test/java/org/apache/james/mime4j/mboxiterator/MboxIteratorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/mbox/src/test/java/org/apache/james/mime4j/mboxiterator/MboxIteratorTest.java?rev=1351620&r1=1351619&r2=1351620&view=diff
==============================================================================
--- james/mime4j/trunk/mbox/src/test/java/org/apache/james/mime4j/mboxiterator/MboxIteratorTest.java
(original)
+++ james/mime4j/trunk/mbox/src/test/java/org/apache/james/mime4j/mboxiterator/MboxIteratorTest.java
Tue Jun 19 09:41:33 2012
@@ -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 class MboxIteratorTest {
     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();
+    }
+
 }

Modified: james/mime4j/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/pom.xml?rev=1351620&r1=1351619&r2=1351620&view=diff
==============================================================================
--- james/mime4j/trunk/pom.xml (original)
+++ james/mime4j/trunk/pom.xml Tue Jun 19 09:41:33 2012
@@ -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>
 



Mime
View raw message