summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/main/java/org/simpleframework/http/message/PartEntryFactory.java
blob: aba57388822095ed2d9c1cca107981e9afe99d14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * PartEntryFactory.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;

/**
 * This <code>PartEntryFactory</code> object provides a factory for
 * creating part entry consumers. The part entry consumers created
 * read individual entries from a list of parts within a stream. 
 * This is basically a convenience factory for the list consumer.
 * 
 * @author Niall Gallagher
 * 
 * @see org.simpleframework.http.message.PartSeriesConsumer
 */
class PartEntryFactory {   

   /**
    * This is used to accumulate all the parts of the upload.
    */ 
   private final PartSeries series;   
   
   /**
    * This is used to allocate the buffers used by the entry.
    */ 
   private final Allocator allocator;
   
   /**
    * This is the terminal token used to delimiter the upload.
    */ 
   private final byte[] terminal;
   
   /**
    * This is the length of the parent part series body.
    */
   private final long length;
   
   /**
    * Constructor for the <code>PartEntryFactory</code> object.
    * This is used to create a factory for entry consumers that
    * can be used to read an entry from a part list.
    * 
    * @param allocator this is the allocator used for buffers
    * @param series this is the list of parts that are extracted
    * @param terminal this is the terminal buffer to be used
    * @param length this is the length of the parent part series     
    */
   public PartEntryFactory(Allocator allocator, PartSeries series, byte[] terminal, long length) {
      this.allocator = allocator;
      this.terminal = terminal;
      this.series = series;
      this.length = length;
   }
   
   
   /**
    * This creates a new part entry consumer that can be used to
    * read the next part from the list. The consumer instantiated
    * by this factory acquires the allocator, list and boundary 
    * from the enclosing part list consumer instance.
    * 
    * @return a part entry consumer for this part list consumer 
    */
   public PartEntryConsumer getInstance() {
      return new PartEntryConsumer(allocator, series, terminal, length);
   }
}