Skip to content

Commit

Permalink
Moved all copy / parse methods to MimeBuilder class
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Jan 17, 2011
1 parent a6060c4 commit aa45e1b
Show file tree
Hide file tree
Showing 19 changed files with 453 additions and 458 deletions.
Expand Up @@ -26,7 +26,7 @@

import org.apache.james.mime4j.codec.CodecUtil;
import org.apache.james.mime4j.dom.Header;
import org.apache.james.mime4j.message.MessageImpl;
import org.apache.james.mime4j.message.MimeBuilder;
import org.apache.james.mime4j.message.SimpleContentHandler;
import org.apache.james.mime4j.parser.AbstractContentHandler;
import org.apache.james.mime4j.parser.ContentHandler;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static void main(String[] args) throws Exception {
System.out.println("No of repetitions: " + repetitions);
System.out.println("Content length: " + content.length);
System.out.println("Test: " + test.getClass().getSimpleName());

System.out.print("Warmup... ");
long t0 = System.currentTimeMillis();
while (System.currentTimeMillis() - t0 < 1500) {
Expand Down Expand Up @@ -171,7 +171,7 @@ public void run(byte[] content, int repetitions) throws Exception {
DefaultStorageProvider.setInstance(new MemoryStorageProvider());

for (int i = 0; i < repetitions; i++) {
new MessageImpl(new ByteArrayInputStream(content));
MimeBuilder.parse(new ByteArrayInputStream(content));
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions dom/src/main/java/org/apache/james/mime4j/dom/Entity.java
Expand Up @@ -78,6 +78,16 @@ public interface Entity extends Disposable {
*/
Body removeBody();

/**
* Determines if the MIME type of this <code>Entity</code> is
* <code>multipart/*</code>. Since multipart-entities must have
* a boundary parameter in the <code>Content-Type</code> field this
* method returns <code>false</code> if no boundary exists.
*
* @return <code>true</code> on match, <code>false</code> otherwise.
*/
boolean isMultipart();

/**
* Determines the MIME type of this <code>Entity</code>. The MIME type
* is derived by looking at the parent's Content-Type field if no
Expand Down
74 changes: 0 additions & 74 deletions dom/src/main/java/org/apache/james/mime4j/message/BodyCopier.java

This file was deleted.

33 changes: 0 additions & 33 deletions dom/src/main/java/org/apache/james/mime4j/message/BodyPart.java
Expand Up @@ -22,11 +22,6 @@
import java.util.Date;
import java.util.Map;

import org.apache.james.mime4j.dom.Body;
import org.apache.james.mime4j.dom.Entity;
import org.apache.james.mime4j.dom.Message;
import org.apache.james.mime4j.dom.Multipart;
import org.apache.james.mime4j.dom.SingleBody;
import org.apache.james.mime4j.dom.field.ContentDispositionField;
import org.apache.james.mime4j.dom.field.ContentTransferEncodingField;
import org.apache.james.mime4j.dom.field.ContentTypeField;
Expand All @@ -46,34 +41,6 @@ public class BodyPart extends EntityBase {
public BodyPart() {
}

/**
* Creates a new <code>BodyPart</code> from the specified
* <code>BodyPart</code>. The <code>BodyPart</code> instance is initialized
* with copies of header and body of the specified <code>BodyPart</code>.
* The parent entity of the new body part is <code>null</code>.
*
* @param other
* body part to copy.
* @throws UnsupportedOperationException
* if <code>other</code> contains a {@link SingleBody} that
* does not support the {@link SingleBody#copy() copy()}
* operation.
* @throws IllegalArgumentException
* if <code>other</code> contains a <code>Body</code> that
* is neither a {@link Message}, {@link Multipart} or
* {@link SingleBody}.
*/
public BodyPart(Entity other) {
if (other.getHeader() != null) {
setHeader(new HeaderImpl(other.getHeader()));
}

if (other.getBody() != null) {
Body bodyCopy = BodyCopier.copy(other.getBody());
setBody(bodyCopy);
}
}

@Override
protected String newUniqueBoundary() {
return MimeUtil.createUniqueBoundary();
Expand Down
Expand Up @@ -43,7 +43,7 @@
* A <code>ContentHandler</code> for building an <code>Entity</code> to be
* used in conjunction with a {@link org.apache.james.mime4j.parser.MimeStreamParser}.
*/
public class EntityBuilder implements ContentHandler {
class EntityBuilder implements ContentHandler {

private final Entity entity;
private final BodyFactory bodyFactory;
Expand Down
59 changes: 0 additions & 59 deletions dom/src/main/java/org/apache/james/mime4j/message/HeaderImpl.java
Expand Up @@ -19,19 +19,6 @@

package org.apache.james.mime4j.message;

import java.io.IOException;
import java.io.InputStream;

import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.MimeIOException;
import org.apache.james.mime4j.codec.DecodeMonitor;
import org.apache.james.mime4j.dom.Header;
import org.apache.james.mime4j.dom.field.Field;
import org.apache.james.mime4j.field.DefaultFieldParser;
import org.apache.james.mime4j.parser.AbstractContentHandler;
import org.apache.james.mime4j.parser.MimeStreamParser;
import org.apache.james.mime4j.stream.RawField;

/**
* The header of an entity (see RFC 2045).
*/
Expand All @@ -43,50 +30,4 @@ public class HeaderImpl extends HeaderBase {
public HeaderImpl() {
}

/**
* Creates a new <code>Header</code> from the specified
* <code>Header</code>. The <code>Header</code> instance is initialized
* with a copy of the list of {@link Field}s of the specified
* <code>Header</code>. The <code>Field</code> objects are not copied
* because they are immutable and can safely be shared between headers.
*
* @param other
* header to copy.
*/
public HeaderImpl(Header other) {
for (Field otherField : other.getFields()) {
addField(otherField);
}
}

/**
* Creates a new <code>Header</code> from the specified stream.
*
* @param is the stream to read the header from.
*
* @throws IOException on I/O errors.
* @throws MimeIOException on MIME protocol violations.
*/
public HeaderImpl(
final InputStream is,
final DecodeMonitor monitor) throws IOException, MimeIOException {
final MimeStreamParser parser = new MimeStreamParser();
parser.setContentHandler(new AbstractContentHandler() {
@Override
public void endHeader() {
parser.stop();
}
@Override
public void field(RawField field) throws MimeException {
Field parsedField = DefaultFieldParser.parse(field.getRaw(), monitor);
addField(parsedField);
}
});
try {
parser.parse(is);
} catch (MimeException ex) {
throw new MimeIOException(ex);
}
}

}
Expand Up @@ -34,12 +34,18 @@ public Message newMessage() {

@Override
public Message newMessage(Message source) {
return new MessageImpl(source);
return MimeBuilder.copy(source);
}

@Override
public Message parse(InputStream source) throws MimeException, IOException {
return new MessageImpl(source, mimeEntityConfig, storageProvider, mutableBodyDescriptorFactory, decodeMonitor, contentDecoding, flatMode);
return MimeBuilder.parse(source,
mimeEntityConfig,
storageProvider,
mutableBodyDescriptorFactory,
decodeMonitor,
contentDecoding,
flatMode);
}

@Override
Expand Down

0 comments on commit aa45e1b

Please sign in to comment.