summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/main/java/org/simpleframework/http/message/PartFactory.java
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2015-06-24 14:31:11 +0200
committerMikael Peltier <mikaelpeltier@google.com>2015-06-24 14:59:36 +0000
commit04563874ddaac702d6c715eaa89c29b253f4c54e (patch)
treec305fa98670c3e80be494cc054a8e31b51bfe7f2 /simple/simple-http/src/main/java/org/simpleframework/http/message/PartFactory.java
parentf1828481ebcfee3bddc323fca178a4502a60ceef (diff)
downloadtoolchain_jack-04563874ddaac702d6c715eaa89c29b253f4c54e.zip
toolchain_jack-04563874ddaac702d6c715eaa89c29b253f4c54e.tar.gz
toolchain_jack-04563874ddaac702d6c715eaa89c29b253f4c54e.tar.bz2
Add simpleframework source files
Change-Id: I18d01df16de2868ca5458f79a88e6070b75db2c3 (cherry picked from commit 3e9f84cf7b22f6970eb8041ca38d12d75c6bb270)
Diffstat (limited to 'simple/simple-http/src/main/java/org/simpleframework/http/message/PartFactory.java')
-rw-r--r--simple/simple-http/src/main/java/org/simpleframework/http/message/PartFactory.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/simple/simple-http/src/main/java/org/simpleframework/http/message/PartFactory.java b/simple/simple-http/src/main/java/org/simpleframework/http/message/PartFactory.java
new file mode 100644
index 0000000..f394ba6
--- /dev/null
+++ b/simple/simple-http/src/main/java/org/simpleframework/http/message/PartFactory.java
@@ -0,0 +1,78 @@
+/*
+ * PartFactory.java February 2007
+ *
+ * Copyright (C) 2007, Niall Gallagher <niallg@users.sf.net>
+ *
+ * Licensed 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.simpleframework.http.message;
+
+import org.simpleframework.common.buffer.Allocator;
+
+/**
+ * The <code>PartFactory</code> represents a factory for creating the
+ * consumers that are used to read a multipart upload message. This
+ * supports two types of consumers for the multipart upload, lists
+ * and bodies. A part list is basically a collection of parts and or
+ * part lists. The part type is determined from the part header.
+ *
+ * @author Niall Gallagher
+ *
+ * @see org.simpleframework.http.message.PartSeriesConsumer
+ * @see org.simpleframework.http.message.PartBodyConsumer
+ */
+class PartFactory extends ConsumerFactory {
+
+ /**
+ * This is the overall length of the parent part series.
+ */
+ private final long length;
+
+ /**
+ * Constructor for the <code>PartFactory</code> object. This is
+ * used to create a factory using a buffer allocator, which will
+ * create a buffer for accumulating the entire message body,
+ * also to ensure the correct part type is created this requires
+ * the header information for the part.
+ *
+ * @param allocator this is used to allocate the internal buffer
+ * @param header this is used to determine the part type
+ * @param length this is the length of the parent part series
+ */
+ public PartFactory(Allocator allocator, Segment header, long length) {
+ super(allocator, header);
+ this.length = length;
+ }
+
+ /**
+ * This method is used to create the consumer given the list and
+ * boundary for the part. In order to determine the part type
+ * this will consult the header consumed for the part. Depending
+ * on whether it is a list or body a suitable consumer is created.
+ *
+ * @param series this is the list used to collect the parts
+ * @param boundary this is the boundary used to terminate the part
+ *
+ * @return this will return the consumer for the part body
+ */
+ public BodyConsumer getInstance(PartSeries series, byte[] boundary) {
+ byte[] terminal = getBoundary(segment);
+
+ if(isUpload(segment)) {
+ return new PartSeriesConsumer(allocator, series, terminal, length);
+ }
+ return new PartBodyConsumer(allocator, segment, series, boundary);
+ }
+}
+