james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r778457 [1/13] - in /james/mime4j/trunk: benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/codec/ core/src/main/java/org/apache/james/mime4j/descriptor/ c...
Date Mon, 25 May 2009 17:20:52 GMT
Author: mwiederkehr
Date: Mon May 25 17:20:48 2009
New Revision: 778457

URL: http://svn.apache.org/viewvc?rev=778457&view=rev
Log:
set svn:eol-style=native on all Java source files

Modified:
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64InputStreamBench.java   (props changed)
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64OutputStreamBench.java   (props changed)
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeIOException.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64InputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64OutputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/ByteQueue.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/UnboundedFifoByteBuffer.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/descriptor/BodyDescriptor.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/descriptor/ContentDescriptor.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/descriptor/DefaultBodyDescriptor.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/descriptor/MaximalBodyDescriptor.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/descriptor/MutableBodyDescriptor.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/AbstractField.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/AddressListField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/ContentDispositionField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/ContentTypeField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/DateTimeField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/FieldName.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/FieldParser.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/Fields.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/MailboxField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/MailboxListField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/ParseException.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/ParsedField.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/UnstructuredField.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/Address.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/AddressList.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/Builder.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/DomainList.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/Group.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/Mailbox.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/MailboxList.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/parser/BaseNode.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/EOLConvertingInputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberInputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberSource.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptor.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/PositionInputStream.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Body.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyFactory.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Entity.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Header.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Message.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Multipart.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StorageBinaryBody.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StorageTextBody.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StringTextBody.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/TextBody.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/AbstractContentHandler.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/ContentHandler.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/EntityStateMachine.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/EntityStates.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/Event.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/Field.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeEntity.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeParseEventException.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeTokenStream.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/RawEntity.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/RawField.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/RecursionMode.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/AbstractStorageProvider.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/CipherStorageProvider.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/DefaultStorageProvider.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/MemoryStorageProvider.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/MultiReferenceStorage.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/Storage.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/StorageOutputStream.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/StorageProvider.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/TempFileStorageProvider.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/storage/ThresholdStorageProvider.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ByteArrayBuffer.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ByteSequence.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/CharsetUtil.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ContentUtil.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/EmptyByteSequence.java   (props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/MimeUtil.java   (contents, props changed)
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/StringArrayMap.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/EncodeUtils.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/TestUtil.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/BaseTestForBodyDescriptors.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/DefaultBodyDescriptorTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/MaximalBodyDescriptorTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/FieldTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/UnstructuredFieldTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/contentdisposition/ContentDispositionTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/contenttype/ContentTypeTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/mimeversion/MimeVersionParserTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/structured/StructuredFieldParserTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineNumberInputStreamTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/HeaderTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageWriteToTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/SingleBodyCopyTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeEntityTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamTokenMessageRfc822Test.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeTokenEmbeddedMessageTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeTokenNoRecurseTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeTokenStreamBodyDescriptorTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeTokenStreamReaderTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeTokenStreamTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MultipartStreamTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MultipartTokensTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/StrictMimeTokenStreamTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/storage/DefaultStorageProviderTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/storage/MultiReferenceStorageTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/CharsetUtilTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/MimeUtilTest.java   (props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/StringArrayMapTest.java   (contents, props changed)
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/TestByteArrayBuffer.java   (props changed)
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java   (props changed)
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java   (props changed)
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java   (props changed)
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java   (props changed)

Propchange: james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64InputStreamBench.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64OutputStreamBench.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeIOException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64InputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64InputStream.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64InputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64InputStream.java Mon May 25 17:20:48 2009
@@ -1,280 +1,280 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.codec;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Performs Base-64 decoding on an underlying stream.
- */
-public class Base64InputStream extends InputStream {
-    private static Log log = LogFactory.getLog(Base64InputStream.class);
-
-    private static final int ENCODED_BUFFER_SIZE = 1536;
-
-    private static final int[] BASE64_DECODE = new int[256];
-
-    static {
-        for (int i = 0; i < 256; i++)
-            BASE64_DECODE[i] = -1;
-        for (int i = 0; i < Base64OutputStream.BASE64_TABLE.length; i++)
-            BASE64_DECODE[Base64OutputStream.BASE64_TABLE[i] & 0xff] = i;
-    }
-
-    private static final byte BASE64_PAD = '=';
-
-    private static final int EOF = -1;
-
-    private final byte[] singleByte = new byte[1];
-
-    private boolean strict;
-
-    private final InputStream in;
-    private boolean closed = false;
-
-    private final byte[] encoded = new byte[ENCODED_BUFFER_SIZE];
-    private int position = 0; // current index into encoded buffer
-    private int size = 0; // current size of encoded buffer
-
-    private final ByteQueue q = new ByteQueue();
-
-    private boolean eof; // end of file or pad character reached
-
-    public Base64InputStream(InputStream in) {
-        this(in, false);
-    }
-
-    public Base64InputStream(InputStream in, boolean strict) {
-        if (in == null)
-            throw new IllegalArgumentException();
-
-        this.in = in;
-        this.strict = strict;
-    }
-
-    @Override
-    public int read() throws IOException {
-        if (closed)
-            throw new IOException("Base64InputStream has been closed");
-
-        while (true) {
-            int bytes = read0(singleByte, 0, 1);
-            if (bytes == EOF)
-                return EOF;
-
-            if (bytes == 1)
-                return singleByte[0] & 0xff;
-        }
-    }
-
-    @Override
-    public int read(byte[] buffer) throws IOException {
-        if (closed)
-            throw new IOException("Base64InputStream has been closed");
-
-        if (buffer == null)
-            throw new NullPointerException();
-
-        if (buffer.length == 0)
-            return 0;
-
-        return read0(buffer, 0, buffer.length);
-    }
-
-    @Override
-    public int read(byte[] buffer, int offset, int length) throws IOException {
-        if (closed)
-            throw new IOException("Base64InputStream has been closed");
-
-        if (buffer == null)
-            throw new NullPointerException();
-
-        if (offset < 0 || length < 0 || offset + length > buffer.length)
-            throw new IndexOutOfBoundsException();
-
-        if (length == 0)
-            return 0;
-
-        return read0(buffer, offset, offset + length);
-    }
-
-    @Override
-    public void close() throws IOException {
-        if (closed)
-            return;
-
-        closed = true;
-    }
-
-    private int read0(final byte[] buffer, final int from, final int to)
-            throws IOException {
-        int index = from; // index into given buffer
-
-        // check if a previous invocation left decoded bytes in the queue
-
-        int qCount = q.count();
-        while (qCount-- > 0 && index < to) {
-            buffer[index++] = q.dequeue();
-        }
-
-        // eof or pad reached?
-
-        if (eof)
-            return index == from ? EOF : index - from;
-
-        // decode into given buffer
-
-        int data = 0; // holds decoded data; up to four sextets
-        int sextets = 0; // number of sextets
-
-        while (index < to) {
-            // make sure buffer not empty
-
-            while (position == size) {
-                int n = in.read(encoded, 0, encoded.length);
-                if (n == EOF) {
-                    eof = true;
-
-                    if (sextets != 0) {
-                        // error in encoded data
-                        handleUnexpectedEof(sextets);
-                    }
-
-                    return index == from ? EOF : index - from;
-                } else if (n > 0) {
-                    position = 0;
-                    size = n;
-                } else {
-                    assert n == 0;
-                }
-            }
-
-            // decode buffer
-
-            while (position < size && index < to) {
-                int value = encoded[position++] & 0xff;
-
-                if (value == BASE64_PAD) {
-                    index = decodePad(data, sextets, buffer, index, to);
-                    return index - from;
-                }
-
-                int decoded = BASE64_DECODE[value];
-                if (decoded < 0) // -1: not a base64 char
-                    continue;
-
-                data = (data << 6) | decoded;
-                sextets++;
-
-                if (sextets == 4) {
-                    sextets = 0;
-
-                    byte b1 = (byte) (data >>> 16);
-                    byte b2 = (byte) (data >>> 8);
-                    byte b3 = (byte) data;
-
-                    if (index < to - 2) {
-                        buffer[index++] = b1;
-                        buffer[index++] = b2;
-                        buffer[index++] = b3;
-                    } else {
-                        if (index < to - 1) {
-                            buffer[index++] = b1;
-                            buffer[index++] = b2;
-                            q.enqueue(b3);
-                        } else if (index < to) {
-                            buffer[index++] = b1;
-                            q.enqueue(b2);
-                            q.enqueue(b3);
-                        } else {
-                            q.enqueue(b1);
-                            q.enqueue(b2);
-                            q.enqueue(b3);
-                        }
-
-                        assert index == to;
-                        return to - from;
-                    }
-                }
-            }
-        }
-
-        assert sextets == 0;
-        assert index == to;
-        return to - from;
-    }
-
-    private int decodePad(int data, int sextets, final byte[] buffer,
-            int index, final int end) throws IOException {
-        eof = true;
-
-        if (sextets == 2) {
-            // one byte encoded as "XY=="
-
-            byte b = (byte) (data >>> 4);
-            if (index < end) {
-                buffer[index++] = b;
-            } else {
-                q.enqueue(b);
-            }
-        } else if (sextets == 3) {
-            // two bytes encoded as "XYZ="
-
-            byte b1 = (byte) (data >>> 10);
-            byte b2 = (byte) ((data >>> 2) & 0xFF);
-
-            if (index < end - 1) {
-                buffer[index++] = b1;
-                buffer[index++] = b2;
-            } else if (index < end) {
-                buffer[index++] = b1;
-                q.enqueue(b2);
-            } else {
-                q.enqueue(b1);
-                q.enqueue(b2);
-            }
-        } else {
-            // error in encoded data
-            handleUnexpecedPad(sextets);
-        }
-
-        return index;
-    }
-
-    private void handleUnexpectedEof(int sextets) throws IOException {
-        if (strict)
-            throw new IOException("unexpected end of file");
-        else
-            log.warn("unexpected end of file; dropping " + sextets
-                    + " sextet(s)");
-    }
-
-    private void handleUnexpecedPad(int sextets) throws IOException {
-        if (strict)
-            throw new IOException("unexpected padding character");
-        else
-            log.warn("unexpected padding character; dropping " + sextets
-                    + " sextet(s)");
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.codec;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Performs Base-64 decoding on an underlying stream.
+ */
+public class Base64InputStream extends InputStream {
+    private static Log log = LogFactory.getLog(Base64InputStream.class);
+
+    private static final int ENCODED_BUFFER_SIZE = 1536;
+
+    private static final int[] BASE64_DECODE = new int[256];
+
+    static {
+        for (int i = 0; i < 256; i++)
+            BASE64_DECODE[i] = -1;
+        for (int i = 0; i < Base64OutputStream.BASE64_TABLE.length; i++)
+            BASE64_DECODE[Base64OutputStream.BASE64_TABLE[i] & 0xff] = i;
+    }
+
+    private static final byte BASE64_PAD = '=';
+
+    private static final int EOF = -1;
+
+    private final byte[] singleByte = new byte[1];
+
+    private boolean strict;
+
+    private final InputStream in;
+    private boolean closed = false;
+
+    private final byte[] encoded = new byte[ENCODED_BUFFER_SIZE];
+    private int position = 0; // current index into encoded buffer
+    private int size = 0; // current size of encoded buffer
+
+    private final ByteQueue q = new ByteQueue();
+
+    private boolean eof; // end of file or pad character reached
+
+    public Base64InputStream(InputStream in) {
+        this(in, false);
+    }
+
+    public Base64InputStream(InputStream in, boolean strict) {
+        if (in == null)
+            throw new IllegalArgumentException();
+
+        this.in = in;
+        this.strict = strict;
+    }
+
+    @Override
+    public int read() throws IOException {
+        if (closed)
+            throw new IOException("Base64InputStream has been closed");
+
+        while (true) {
+            int bytes = read0(singleByte, 0, 1);
+            if (bytes == EOF)
+                return EOF;
+
+            if (bytes == 1)
+                return singleByte[0] & 0xff;
+        }
+    }
+
+    @Override
+    public int read(byte[] buffer) throws IOException {
+        if (closed)
+            throw new IOException("Base64InputStream has been closed");
+
+        if (buffer == null)
+            throw new NullPointerException();
+
+        if (buffer.length == 0)
+            return 0;
+
+        return read0(buffer, 0, buffer.length);
+    }
+
+    @Override
+    public int read(byte[] buffer, int offset, int length) throws IOException {
+        if (closed)
+            throw new IOException("Base64InputStream has been closed");
+
+        if (buffer == null)
+            throw new NullPointerException();
+
+        if (offset < 0 || length < 0 || offset + length > buffer.length)
+            throw new IndexOutOfBoundsException();
+
+        if (length == 0)
+            return 0;
+
+        return read0(buffer, offset, offset + length);
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (closed)
+            return;
+
+        closed = true;
+    }
+
+    private int read0(final byte[] buffer, final int from, final int to)
+            throws IOException {
+        int index = from; // index into given buffer
+
+        // check if a previous invocation left decoded bytes in the queue
+
+        int qCount = q.count();
+        while (qCount-- > 0 && index < to) {
+            buffer[index++] = q.dequeue();
+        }
+
+        // eof or pad reached?
+
+        if (eof)
+            return index == from ? EOF : index - from;
+
+        // decode into given buffer
+
+        int data = 0; // holds decoded data; up to four sextets
+        int sextets = 0; // number of sextets
+
+        while (index < to) {
+            // make sure buffer not empty
+
+            while (position == size) {
+                int n = in.read(encoded, 0, encoded.length);
+                if (n == EOF) {
+                    eof = true;
+
+                    if (sextets != 0) {
+                        // error in encoded data
+                        handleUnexpectedEof(sextets);
+                    }
+
+                    return index == from ? EOF : index - from;
+                } else if (n > 0) {
+                    position = 0;
+                    size = n;
+                } else {
+                    assert n == 0;
+                }
+            }
+
+            // decode buffer
+
+            while (position < size && index < to) {
+                int value = encoded[position++] & 0xff;
+
+                if (value == BASE64_PAD) {
+                    index = decodePad(data, sextets, buffer, index, to);
+                    return index - from;
+                }
+
+                int decoded = BASE64_DECODE[value];
+                if (decoded < 0) // -1: not a base64 char
+                    continue;
+
+                data = (data << 6) | decoded;
+                sextets++;
+
+                if (sextets == 4) {
+                    sextets = 0;
+
+                    byte b1 = (byte) (data >>> 16);
+                    byte b2 = (byte) (data >>> 8);
+                    byte b3 = (byte) data;
+
+                    if (index < to - 2) {
+                        buffer[index++] = b1;
+                        buffer[index++] = b2;
+                        buffer[index++] = b3;
+                    } else {
+                        if (index < to - 1) {
+                            buffer[index++] = b1;
+                            buffer[index++] = b2;
+                            q.enqueue(b3);
+                        } else if (index < to) {
+                            buffer[index++] = b1;
+                            q.enqueue(b2);
+                            q.enqueue(b3);
+                        } else {
+                            q.enqueue(b1);
+                            q.enqueue(b2);
+                            q.enqueue(b3);
+                        }
+
+                        assert index == to;
+                        return to - from;
+                    }
+                }
+            }
+        }
+
+        assert sextets == 0;
+        assert index == to;
+        return to - from;
+    }
+
+    private int decodePad(int data, int sextets, final byte[] buffer,
+            int index, final int end) throws IOException {
+        eof = true;
+
+        if (sextets == 2) {
+            // one byte encoded as "XY=="
+
+            byte b = (byte) (data >>> 4);
+            if (index < end) {
+                buffer[index++] = b;
+            } else {
+                q.enqueue(b);
+            }
+        } else if (sextets == 3) {
+            // two bytes encoded as "XYZ="
+
+            byte b1 = (byte) (data >>> 10);
+            byte b2 = (byte) ((data >>> 2) & 0xFF);
+
+            if (index < end - 1) {
+                buffer[index++] = b1;
+                buffer[index++] = b2;
+            } else if (index < end) {
+                buffer[index++] = b1;
+                q.enqueue(b2);
+            } else {
+                q.enqueue(b1);
+                q.enqueue(b2);
+            }
+        } else {
+            // error in encoded data
+            handleUnexpecedPad(sextets);
+        }
+
+        return index;
+    }
+
+    private void handleUnexpectedEof(int sextets) throws IOException {
+        if (strict)
+            throw new IOException("unexpected end of file");
+        else
+            log.warn("unexpected end of file; dropping " + sextets
+                    + " sextet(s)");
+    }
+
+    private void handleUnexpecedPad(int sextets) throws IOException {
+        if (strict)
+            throw new IOException("unexpected padding character");
+        else
+            log.warn("unexpected padding character; dropping " + sextets
+                    + " sextet(s)");
+    }
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64InputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64OutputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64OutputStream.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64OutputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64OutputStream.java Mon May 25 17:20:48 2009
@@ -1,321 +1,321 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.codec;
-
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * This class implements section <cite>6.8. Base64 Content-Transfer-Encoding</cite>
- * from RFC 2045 <cite>Multipurpose Internet Mail Extensions (MIME) Part One:
- * Format of Internet Message Bodies</cite> by Freed and Borenstein.
- * <p>
- * Code is based on Base64 and Base64OutputStream code from Commons-Codec 1.4.
- * 
- * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
- */
-public class Base64OutputStream extends FilterOutputStream {
-
-    // Default line length per RFC 2045 section 6.8.
-    private static final int DEFAULT_LINE_LENGTH = 76;
-
-    // CRLF line separator per RFC 2045 section 2.1.
-    private static final byte[] CRLF_SEPARATOR = { '\r', '\n' };
-
-    // This array is a lookup table that translates 6-bit positive integer index
-    // values into their "Base64 Alphabet" equivalents as specified in Table 1
-    // of RFC 2045.
-    static final byte[] BASE64_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F',
-            'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
-            'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
-            'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
-            't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
-            '6', '7', '8', '9', '+', '/' };
-
-    // Byte used to pad output.
-    private static final byte BASE64_PAD = '=';
-
-    // This set contains all base64 characters including the pad character. Used
-    // solely to check if a line separator contains any of these characters.
-    private static final Set<Byte> BASE64_CHARS = new HashSet<Byte>();
-
-    static {
-        for (byte b : BASE64_TABLE) {
-            BASE64_CHARS.add(b);
-        }
-        BASE64_CHARS.add(BASE64_PAD);
-    }
-
-    // Mask used to extract 6 bits
-    private static final int MASK_6BITS = 0x3f;
-
-    private static final int ENCODED_BUFFER_SIZE = 2048;
-
-    private final byte[] singleByte = new byte[1];
-
-    private final int lineLength;
-    private final byte[] lineSeparator;
-
-    private boolean closed = false;
-
-    private final byte[] encoded;
-    private int position = 0;
-
-    private int data = 0;
-    private int modulus = 0;
-
-    private int linePosition = 0;
-
-    /**
-     * Creates a <code>Base64OutputStream</code> that writes the encoded data
-     * to the given output stream using the default line length (76) and line
-     * separator (CRLF).
-     * 
-     * @param out
-     *            underlying output stream.
-     */
-    public Base64OutputStream(OutputStream out) {
-        this(out, DEFAULT_LINE_LENGTH, CRLF_SEPARATOR);
-    }
-
-    /**
-     * Creates a <code>Base64OutputStream</code> that writes the encoded data
-     * to the given output stream using the given line length and the default
-     * line separator (CRLF).
-     * <p>
-     * The given line length will be rounded up to the nearest multiple of 4. If
-     * the line length is zero then the output will not be split into lines.
-     * 
-     * @param out
-     *            underlying output stream.
-     * @param lineLength
-     *            desired line length.
-     */
-    public Base64OutputStream(OutputStream out, int lineLength) {
-        this(out, lineLength, CRLF_SEPARATOR);
-    }
-
-    /**
-     * Creates a <code>Base64OutputStream</code> that writes the encoded data
-     * to the given output stream using the given line length and line
-     * separator.
-     * <p>
-     * The given line length will be rounded up to the nearest multiple of 4. If
-     * the line length is zero then the output will not be split into lines and
-     * the line separator is ignored.
-     * <p>
-     * The line separator must not include characters from the BASE64 alphabet
-     * (including the padding character <code>=</code>).
-     * 
-     * @param out
-     *            underlying output stream.
-     * @param lineLength
-     *            desired line length.
-     * @param lineSeparator
-     *            line separator to use.
-     */
-    public Base64OutputStream(OutputStream out, int lineLength,
-            byte[] lineSeparator) {
-        super(out);
-
-        if (out == null)
-            throw new IllegalArgumentException();
-        if (lineLength < 0)
-            throw new IllegalArgumentException();
-        checkLineSeparator(lineSeparator);
-
-        this.lineLength = lineLength;
-        this.lineSeparator = new byte[lineSeparator.length];
-        System.arraycopy(lineSeparator, 0, this.lineSeparator, 0,
-                lineSeparator.length);
-
-        this.encoded = new byte[ENCODED_BUFFER_SIZE];
-    }
-
-    @Override
-    public final void write(final int b) throws IOException {
-        if (closed)
-            throw new IOException("Base64OutputStream has been closed");
-
-        singleByte[0] = (byte) b;
-        write0(singleByte, 0, 1);
-    }
-
-    @Override
-    public final void write(final byte[] buffer) throws IOException {
-        if (closed)
-            throw new IOException("Base64OutputStream has been closed");
-
-        if (buffer == null)
-            throw new NullPointerException();
-
-        if (buffer.length == 0)
-            return;
-
-        write0(buffer, 0, buffer.length);
-    }
-
-    @Override
-    public final void write(final byte[] buffer, final int offset,
-            final int length) throws IOException {
-        if (closed)
-            throw new IOException("Base64OutputStream has been closed");
-
-        if (buffer == null)
-            throw new NullPointerException();
-
-        if (offset < 0 || length < 0 || offset + length > buffer.length)
-            throw new IndexOutOfBoundsException();
-
-        if (length == 0)
-            return;
-
-        write0(buffer, offset, offset + length);
-    }
-
-    @Override
-    public void flush() throws IOException {
-        if (closed)
-            throw new IOException("Base64OutputStream has been closed");
-
-        flush0();
-    }
-
-    @Override
-    public void close() throws IOException {
-        if (closed)
-            return;
-
-        closed = true;
-        close0();
-    }
-
-    private void write0(final byte[] buffer, final int from, final int to)
-            throws IOException {
-        for (int i = from; i < to; i++) {
-            data = (data << 8) | (buffer[i] & 0xff);
-
-            if (++modulus == 3) {
-                modulus = 0;
-
-                // write line separator if necessary
-
-                if (lineLength > 0 && linePosition >= lineLength) {
-                    // writeLineSeparator() inlined for performance reasons
-
-                    linePosition = 0;
-
-                    if (encoded.length - position < lineSeparator.length)
-                        flush0();
-
-                    for (byte ls : lineSeparator)
-                        encoded[position++] = ls;
-                }
-
-                // encode data into 4 bytes
-
-                if (encoded.length - position < 4)
-                    flush0();
-
-                encoded[position++] = BASE64_TABLE[(data >> 18) & MASK_6BITS];
-                encoded[position++] = BASE64_TABLE[(data >> 12) & MASK_6BITS];
-                encoded[position++] = BASE64_TABLE[(data >> 6) & MASK_6BITS];
-                encoded[position++] = BASE64_TABLE[data & MASK_6BITS];
-
-                linePosition += 4;
-            }
-        }
-    }
-
-    private void flush0() throws IOException {
-        if (position > 0) {
-            out.write(encoded, 0, position);
-            position = 0;
-        }
-    }
-
-    private void close0() throws IOException {
-        if (modulus != 0)
-            writePad();
-
-        // write line separator at the end of the encoded data
-
-        if (lineLength > 0 && linePosition > 0) {
-            writeLineSeparator();
-        }
-
-        flush0();
-    }
-
-    private void writePad() throws IOException {
-        // write line separator if necessary
-
-        if (lineLength > 0 && linePosition >= lineLength) {
-            writeLineSeparator();
-        }
-
-        // encode data into 4 bytes
-
-        if (encoded.length - position < 4)
-            flush0();
-
-        if (modulus == 1) {
-            encoded[position++] = BASE64_TABLE[(data >> 2) & MASK_6BITS];
-            encoded[position++] = BASE64_TABLE[(data << 4) & MASK_6BITS];
-            encoded[position++] = BASE64_PAD;
-            encoded[position++] = BASE64_PAD;
-        } else {
-            assert modulus == 2;
-            encoded[position++] = BASE64_TABLE[(data >> 10) & MASK_6BITS];
-            encoded[position++] = BASE64_TABLE[(data >> 4) & MASK_6BITS];
-            encoded[position++] = BASE64_TABLE[(data << 2) & MASK_6BITS];
-            encoded[position++] = BASE64_PAD;
-        }
-
-        linePosition += 4;
-    }
-
-    private void writeLineSeparator() throws IOException {
-        linePosition = 0;
-
-        if (encoded.length - position < lineSeparator.length)
-            flush0();
-
-        for (byte ls : lineSeparator)
-            encoded[position++] = ls;
-    }
-
-    private void checkLineSeparator(byte[] lineSeparator) {
-        if (lineSeparator.length > ENCODED_BUFFER_SIZE)
-            throw new IllegalArgumentException("line separator length exceeds "
-                    + ENCODED_BUFFER_SIZE);
-
-        for (byte b : lineSeparator) {
-            if (BASE64_CHARS.contains(b)) {
-                throw new IllegalArgumentException(
-                        "line separator must not contain base64 character '"
-                                + (char) (b & 0xff) + "'");
-            }
-        }
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.codec;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * This class implements section <cite>6.8. Base64 Content-Transfer-Encoding</cite>
+ * from RFC 2045 <cite>Multipurpose Internet Mail Extensions (MIME) Part One:
+ * Format of Internet Message Bodies</cite> by Freed and Borenstein.
+ * <p>
+ * Code is based on Base64 and Base64OutputStream code from Commons-Codec 1.4.
+ * 
+ * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
+ */
+public class Base64OutputStream extends FilterOutputStream {
+
+    // Default line length per RFC 2045 section 6.8.
+    private static final int DEFAULT_LINE_LENGTH = 76;
+
+    // CRLF line separator per RFC 2045 section 2.1.
+    private static final byte[] CRLF_SEPARATOR = { '\r', '\n' };
+
+    // This array is a lookup table that translates 6-bit positive integer index
+    // values into their "Base64 Alphabet" equivalents as specified in Table 1
+    // of RFC 2045.
+    static final byte[] BASE64_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F',
+            'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
+            'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+            'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
+            't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
+            '6', '7', '8', '9', '+', '/' };
+
+    // Byte used to pad output.
+    private static final byte BASE64_PAD = '=';
+
+    // This set contains all base64 characters including the pad character. Used
+    // solely to check if a line separator contains any of these characters.
+    private static final Set<Byte> BASE64_CHARS = new HashSet<Byte>();
+
+    static {
+        for (byte b : BASE64_TABLE) {
+            BASE64_CHARS.add(b);
+        }
+        BASE64_CHARS.add(BASE64_PAD);
+    }
+
+    // Mask used to extract 6 bits
+    private static final int MASK_6BITS = 0x3f;
+
+    private static final int ENCODED_BUFFER_SIZE = 2048;
+
+    private final byte[] singleByte = new byte[1];
+
+    private final int lineLength;
+    private final byte[] lineSeparator;
+
+    private boolean closed = false;
+
+    private final byte[] encoded;
+    private int position = 0;
+
+    private int data = 0;
+    private int modulus = 0;
+
+    private int linePosition = 0;
+
+    /**
+     * Creates a <code>Base64OutputStream</code> that writes the encoded data
+     * to the given output stream using the default line length (76) and line
+     * separator (CRLF).
+     * 
+     * @param out
+     *            underlying output stream.
+     */
+    public Base64OutputStream(OutputStream out) {
+        this(out, DEFAULT_LINE_LENGTH, CRLF_SEPARATOR);
+    }
+
+    /**
+     * Creates a <code>Base64OutputStream</code> that writes the encoded data
+     * to the given output stream using the given line length and the default
+     * line separator (CRLF).
+     * <p>
+     * The given line length will be rounded up to the nearest multiple of 4. If
+     * the line length is zero then the output will not be split into lines.
+     * 
+     * @param out
+     *            underlying output stream.
+     * @param lineLength
+     *            desired line length.
+     */
+    public Base64OutputStream(OutputStream out, int lineLength) {
+        this(out, lineLength, CRLF_SEPARATOR);
+    }
+
+    /**
+     * Creates a <code>Base64OutputStream</code> that writes the encoded data
+     * to the given output stream using the given line length and line
+     * separator.
+     * <p>
+     * The given line length will be rounded up to the nearest multiple of 4. If
+     * the line length is zero then the output will not be split into lines and
+     * the line separator is ignored.
+     * <p>
+     * The line separator must not include characters from the BASE64 alphabet
+     * (including the padding character <code>=</code>).
+     * 
+     * @param out
+     *            underlying output stream.
+     * @param lineLength
+     *            desired line length.
+     * @param lineSeparator
+     *            line separator to use.
+     */
+    public Base64OutputStream(OutputStream out, int lineLength,
+            byte[] lineSeparator) {
+        super(out);
+
+        if (out == null)
+            throw new IllegalArgumentException();
+        if (lineLength < 0)
+            throw new IllegalArgumentException();
+        checkLineSeparator(lineSeparator);
+
+        this.lineLength = lineLength;
+        this.lineSeparator = new byte[lineSeparator.length];
+        System.arraycopy(lineSeparator, 0, this.lineSeparator, 0,
+                lineSeparator.length);
+
+        this.encoded = new byte[ENCODED_BUFFER_SIZE];
+    }
+
+    @Override
+    public final void write(final int b) throws IOException {
+        if (closed)
+            throw new IOException("Base64OutputStream has been closed");
+
+        singleByte[0] = (byte) b;
+        write0(singleByte, 0, 1);
+    }
+
+    @Override
+    public final void write(final byte[] buffer) throws IOException {
+        if (closed)
+            throw new IOException("Base64OutputStream has been closed");
+
+        if (buffer == null)
+            throw new NullPointerException();
+
+        if (buffer.length == 0)
+            return;
+
+        write0(buffer, 0, buffer.length);
+    }
+
+    @Override
+    public final void write(final byte[] buffer, final int offset,
+            final int length) throws IOException {
+        if (closed)
+            throw new IOException("Base64OutputStream has been closed");
+
+        if (buffer == null)
+            throw new NullPointerException();
+
+        if (offset < 0 || length < 0 || offset + length > buffer.length)
+            throw new IndexOutOfBoundsException();
+
+        if (length == 0)
+            return;
+
+        write0(buffer, offset, offset + length);
+    }
+
+    @Override
+    public void flush() throws IOException {
+        if (closed)
+            throw new IOException("Base64OutputStream has been closed");
+
+        flush0();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (closed)
+            return;
+
+        closed = true;
+        close0();
+    }
+
+    private void write0(final byte[] buffer, final int from, final int to)
+            throws IOException {
+        for (int i = from; i < to; i++) {
+            data = (data << 8) | (buffer[i] & 0xff);
+
+            if (++modulus == 3) {
+                modulus = 0;
+
+                // write line separator if necessary
+
+                if (lineLength > 0 && linePosition >= lineLength) {
+                    // writeLineSeparator() inlined for performance reasons
+
+                    linePosition = 0;
+
+                    if (encoded.length - position < lineSeparator.length)
+                        flush0();
+
+                    for (byte ls : lineSeparator)
+                        encoded[position++] = ls;
+                }
+
+                // encode data into 4 bytes
+
+                if (encoded.length - position < 4)
+                    flush0();
+
+                encoded[position++] = BASE64_TABLE[(data >> 18) & MASK_6BITS];
+                encoded[position++] = BASE64_TABLE[(data >> 12) & MASK_6BITS];
+                encoded[position++] = BASE64_TABLE[(data >> 6) & MASK_6BITS];
+                encoded[position++] = BASE64_TABLE[data & MASK_6BITS];
+
+                linePosition += 4;
+            }
+        }
+    }
+
+    private void flush0() throws IOException {
+        if (position > 0) {
+            out.write(encoded, 0, position);
+            position = 0;
+        }
+    }
+
+    private void close0() throws IOException {
+        if (modulus != 0)
+            writePad();
+
+        // write line separator at the end of the encoded data
+
+        if (lineLength > 0 && linePosition > 0) {
+            writeLineSeparator();
+        }
+
+        flush0();
+    }
+
+    private void writePad() throws IOException {
+        // write line separator if necessary
+
+        if (lineLength > 0 && linePosition >= lineLength) {
+            writeLineSeparator();
+        }
+
+        // encode data into 4 bytes
+
+        if (encoded.length - position < 4)
+            flush0();
+
+        if (modulus == 1) {
+            encoded[position++] = BASE64_TABLE[(data >> 2) & MASK_6BITS];
+            encoded[position++] = BASE64_TABLE[(data << 4) & MASK_6BITS];
+            encoded[position++] = BASE64_PAD;
+            encoded[position++] = BASE64_PAD;
+        } else {
+            assert modulus == 2;
+            encoded[position++] = BASE64_TABLE[(data >> 10) & MASK_6BITS];
+            encoded[position++] = BASE64_TABLE[(data >> 4) & MASK_6BITS];
+            encoded[position++] = BASE64_TABLE[(data << 2) & MASK_6BITS];
+            encoded[position++] = BASE64_PAD;
+        }
+
+        linePosition += 4;
+    }
+
+    private void writeLineSeparator() throws IOException {
+        linePosition = 0;
+
+        if (encoded.length - position < lineSeparator.length)
+            flush0();
+
+        for (byte ls : lineSeparator)
+            encoded[position++] = ls;
+    }
+
+    private void checkLineSeparator(byte[] lineSeparator) {
+        if (lineSeparator.length > ENCODED_BUFFER_SIZE)
+            throw new IllegalArgumentException("line separator length exceeds "
+                    + ENCODED_BUFFER_SIZE);
+
+        for (byte b : lineSeparator) {
+            if (BASE64_CHARS.contains(b)) {
+                throw new IllegalArgumentException(
+                        "line separator must not contain base64 character '"
+                                + (char) (b & 0xff) + "'");
+            }
+        }
+    }
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/Base64OutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/ByteQueue.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/ByteQueue.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/ByteQueue.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/ByteQueue.java Mon May 25 17:20:48 2009
@@ -1,62 +1,62 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.codec;
-
-import java.util.Iterator;
-
-public class ByteQueue implements Iterable<Byte> {
-
-    private UnboundedFifoByteBuffer buf;
-    private int initialCapacity = -1;
-
-    public ByteQueue() {
-        buf = new UnboundedFifoByteBuffer();
-    }
-
-    public ByteQueue(int initialCapacity) {
-        buf = new UnboundedFifoByteBuffer(initialCapacity);
-        this.initialCapacity = initialCapacity;
-    }
-
-    public void enqueue(byte b) {
-        buf.add(b);
-    }
-
-    public byte dequeue() {
-        return buf.remove();
-    }
-
-    public int count() {
-        return buf.size();
-    }
-
-    public void clear() {
-        if (initialCapacity != -1)
-            buf = new UnboundedFifoByteBuffer(initialCapacity);
-        else
-            buf = new UnboundedFifoByteBuffer();
-    }
-
-    public Iterator<Byte> iterator() {
-        return buf.iterator();
-    }
-
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.codec;
+
+import java.util.Iterator;
+
+public class ByteQueue implements Iterable<Byte> {
+
+    private UnboundedFifoByteBuffer buf;
+    private int initialCapacity = -1;
+
+    public ByteQueue() {
+        buf = new UnboundedFifoByteBuffer();
+    }
+
+    public ByteQueue(int initialCapacity) {
+        buf = new UnboundedFifoByteBuffer(initialCapacity);
+        this.initialCapacity = initialCapacity;
+    }
+
+    public void enqueue(byte b) {
+        buf.add(b);
+    }
+
+    public byte dequeue() {
+        return buf.remove();
+    }
+
+    public int count() {
+        return buf.size();
+    }
+
+    public void clear() {
+        if (initialCapacity != -1)
+            buf = new UnboundedFifoByteBuffer(initialCapacity);
+        else
+            buf = new UnboundedFifoByteBuffer();
+    }
+
+    public Iterator<Byte> iterator() {
+        return buf.iterator();
+    }
+
+
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/ByteQueue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java Mon May 25 17:20:48 2009
@@ -1,107 +1,107 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.codec;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Utility methods related to codecs.
- */
-public class CodecUtil {
-    
-    static final int DEFAULT_ENCODING_BUFFER_SIZE = 1024;
-    
-    /**
-     * Copies the contents of one stream to the other.
-     * @param in not null
-     * @param out not null
-     * @throws IOException
-     */
-    public static void copy(final InputStream in, final OutputStream out) throws IOException {
-        final byte[] buffer = new byte[DEFAULT_ENCODING_BUFFER_SIZE];
-        int inputLength;
-        while (-1 != (inputLength = in.read(buffer))) {
-            out.write(buffer, 0, inputLength);
-        }
-    }
-    
-    /**
-     * Encodes the given stream using Quoted-Printable.
-     * This assumes that stream is binary and therefore escapes
-     * all line endings.
-     * @param in not null
-     * @param out not null
-     * @throws IOException
-     */
-    public static void encodeQuotedPrintableBinary(final InputStream in, final OutputStream out) throws IOException {
-        
-        QuotedPrintableEncoder encoder = new QuotedPrintableEncoder(DEFAULT_ENCODING_BUFFER_SIZE, true);
-        encoder.encode(in, out);
-    }
-    
-    /**
-     * Encodes the given stream using Quoted-Printable.
-     * This assumes that stream is text and therefore does not escape
-     * all line endings.
-     * @param in not null
-     * @param out not null
-     * @throws IOException
-     */
-    public static void encodeQuotedPrintable(final InputStream in, final OutputStream out) throws IOException {
-        final QuotedPrintableEncoder encoder = new QuotedPrintableEncoder(DEFAULT_ENCODING_BUFFER_SIZE, false);
-        encoder.encode(in, out);
-    }
-    
-    /**
-     * Encodes the given stream using base64.
-     *
-     * @param in not null
-     * @param out not null
-     * @throws IOException if an I/O error occurs
-     */
-    public static void encodeBase64(final InputStream in, final OutputStream out) throws IOException {
-        Base64OutputStream b64Out = new Base64OutputStream(out);
-        copy(in, b64Out);
-        b64Out.close();
-    }
-    
-    /**
-     * Wraps the given stream in a Quoted-Printable encoder.
-     * @param out not null
-     * @return encoding outputstream 
-     * @throws IOException
-     */
-    public static OutputStream wrapQuotedPrintable(final OutputStream out, boolean binary) throws IOException {
-        return new QuotedPrintableOutputStream(out, binary);
-    }
-    
-    /**
-     * Wraps the given stream in a Base64 encoder.
-     * @param out not null
-     * @return encoding outputstream 
-     * @throws IOException
-     */
-    public static OutputStream wrapBase64(final OutputStream out) throws IOException {
-        return new Base64OutputStream(out);
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.codec;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Utility methods related to codecs.
+ */
+public class CodecUtil {
+    
+    static final int DEFAULT_ENCODING_BUFFER_SIZE = 1024;
+    
+    /**
+     * Copies the contents of one stream to the other.
+     * @param in not null
+     * @param out not null
+     * @throws IOException
+     */
+    public static void copy(final InputStream in, final OutputStream out) throws IOException {
+        final byte[] buffer = new byte[DEFAULT_ENCODING_BUFFER_SIZE];
+        int inputLength;
+        while (-1 != (inputLength = in.read(buffer))) {
+            out.write(buffer, 0, inputLength);
+        }
+    }
+    
+    /**
+     * Encodes the given stream using Quoted-Printable.
+     * This assumes that stream is binary and therefore escapes
+     * all line endings.
+     * @param in not null
+     * @param out not null
+     * @throws IOException
+     */
+    public static void encodeQuotedPrintableBinary(final InputStream in, final OutputStream out) throws IOException {
+        
+        QuotedPrintableEncoder encoder = new QuotedPrintableEncoder(DEFAULT_ENCODING_BUFFER_SIZE, true);
+        encoder.encode(in, out);
+    }
+    
+    /**
+     * Encodes the given stream using Quoted-Printable.
+     * This assumes that stream is text and therefore does not escape
+     * all line endings.
+     * @param in not null
+     * @param out not null
+     * @throws IOException
+     */
+    public static void encodeQuotedPrintable(final InputStream in, final OutputStream out) throws IOException {
+        final QuotedPrintableEncoder encoder = new QuotedPrintableEncoder(DEFAULT_ENCODING_BUFFER_SIZE, false);
+        encoder.encode(in, out);
+    }
+    
+    /**
+     * Encodes the given stream using base64.
+     *
+     * @param in not null
+     * @param out not null
+     * @throws IOException if an I/O error occurs
+     */
+    public static void encodeBase64(final InputStream in, final OutputStream out) throws IOException {
+        Base64OutputStream b64Out = new Base64OutputStream(out);
+        copy(in, b64Out);
+        b64Out.close();
+    }
+    
+    /**
+     * Wraps the given stream in a Quoted-Printable encoder.
+     * @param out not null
+     * @return encoding outputstream 
+     * @throws IOException
+     */
+    public static OutputStream wrapQuotedPrintable(final OutputStream out, boolean binary) throws IOException {
+        return new QuotedPrintableOutputStream(out, binary);
+    }
+    
+    /**
+     * Wraps the given stream in a Base64 encoder.
+     * @param out not null
+     * @return encoding outputstream 
+     * @throws IOException
+     */
+    public static OutputStream wrapBase64(final OutputStream out) throws IOException {
+        return new Base64OutputStream(out);
+    }
+
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message