Author: olegk
Date: Tue May 14 13:29:53 2013
New Revision: 1482328
URL: http://svn.apache.org/r1482328
Log:
Eliminated duplicate class in dom module
Added:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
(contents, props changed)
- copied, changed from r1482294,
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java
Removed:
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringInputStream.java
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java
Modified:
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java
Modified:
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java?rev=1482328&r1=1482327&r2=1482328&view=diff
==============================================================================
---
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
(original)
+++
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
Tue May 14 13:29:53 2013
@@ -38,6 +38,8 @@ class TextInputStream extends InputStrea
private final CharBuffer cbuf;
private final ByteBuffer bbuf;
+ private int mark = -1;
+
TextInputStream(final CharSequence s, final Charset charset, int
bufferSize) {
super();
this.encoder = charset.newEncoder()
@@ -125,6 +127,24 @@ class TextInputStream extends InputStrea
}
@Override
+ public void mark(int readlimit) {
+ this.mark = this.cbuf.position();
+ }
+
+ @Override
+ public void reset() throws IOException {
+ if (this.mark != -1) {
+ this.cbuf.position(this.mark);
+ this.mark = -1;
+ }
+ }
+
+ @Override
+ public boolean markSupported() {
+ return true;
+ }
+
+ @Override
public void close() throws IOException {
}
Copied:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
(from r1482294,
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java)
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java?p2=james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java&p1=james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java&r1=1482294&r2=1482328&rev=1482328&view=diff
==============================================================================
---
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java
(original)
+++
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
Tue May 14 13:29:53 2013
@@ -17,7 +17,7 @@
* under the License. *
****************************************************************/
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.io;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -31,7 +31,7 @@ import org.apache.james.mime4j.util.Cont
import org.junit.Assert;
import org.junit.Test;
-public class StringInputStreamTest {
+public class TextInputStreamTest {
private static final String SWISS_GERMAN_HELLO = "Gr\374ezi_z\344m\344";
private static final String RUSSIAN_HELLO =
"\u0412\u0441\u0435\u043C_\u043F\u0440\u0438\u0432\u0435\u0442";
@@ -48,7 +48,7 @@ public class StringInputStreamTest {
private static void singleByteReadTest(final String testString) throws
IOException {
byte[] bytes = ContentUtil.toByteArray(testString, Charsets.UTF_8);
- InputStream in = new StringInputStream(testString, Charsets.UTF_8);
+ InputStream in = new TextInputStream(testString, Charsets.UTF_8, 1024);
for (byte b : bytes) {
int read = in.read();
assertTrue(read >= 0);
@@ -62,7 +62,7 @@ public class StringInputStreamTest {
private static void bufferedReadTest(final String testString) throws
IOException {
SecureRandom rnd = new SecureRandom();
byte[] expected = ContentUtil.toByteArray(testString, Charsets.UTF_8);
- InputStream in = new StringInputStream(testString, Charsets.UTF_8);
+ InputStream in = new TextInputStream(testString, Charsets.UTF_8, 1024);
byte[] buffer = new byte[128];
int offset = 0;
while (true) {
@@ -108,7 +108,7 @@ public class StringInputStreamTest {
@Test
public void testReadZero() throws Exception {
- InputStream r = new StringInputStream("test", Charsets.UTF_8);
+ InputStream r = new TextInputStream("test", Charsets.UTF_8, 1024);
byte[] bytes = new byte[30];
Assert.assertEquals(0, r.read(bytes, 0, 0));
r.close();
@@ -116,7 +116,7 @@ public class StringInputStreamTest {
@Test
public void testSkip() throws Exception {
- InputStream r = new StringInputStream("test", Charsets.UTF_8);
+ InputStream r = new TextInputStream("test", Charsets.UTF_8, 1024);
r.skip(1);
r.skip(2);
Assert.assertEquals('t', r.read());
@@ -127,7 +127,7 @@ public class StringInputStreamTest {
@Test
public void testMarkReset() throws Exception {
- InputStream r = new StringInputStream("test", Charsets.UTF_8);
+ InputStream r = new TextInputStream("test", Charsets.UTF_8, 1024);
r.skip(2);
r.mark(0);
Assert.assertEquals('s', r.read());
Propchange:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java?rev=1482328&r1=1482327&r2=1482328&view=diff
==============================================================================
---
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java
(original)
+++
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java
Tue May 14 13:29:53 2013
@@ -28,6 +28,7 @@ import java.nio.charset.Charset;
import org.apache.james.mime4j.Charsets;
import org.apache.james.mime4j.dom.SingleBody;
import org.apache.james.mime4j.dom.TextBody;
+import org.apache.james.mime4j.io.InputStreams;
class StringBody extends TextBody {
@@ -52,8 +53,8 @@ class StringBody extends TextBody {
@Override
public InputStream getInputStream() throws IOException {
- return new StringInputStream(this.content,
- this.charset != null ? this.charset :
Charsets.DEFAULT_CHARSET, 2048);
+ return InputStreams.create(this.content,
+ this.charset != null ? this.charset :
Charsets.DEFAULT_CHARSET);
}
@Override