View Javadoc
1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http.multipart;
17  
18  import io.netty.buffer.ByteBuf;
19  
20  import java.nio.charset.Charset;
21  
22  /**
23   * Mixed implementation using both in Memory and in File with a limit of size
24   */
25  public class MixedFileUpload extends AbstractMixedHttpData<FileUpload> implements FileUpload {
26  
27      public MixedFileUpload(String name, String filename, String contentType,
28                             String contentTransferEncoding, Charset charset, long size,
29                             long limitSize) {
30          this(name, filename, contentType, contentTransferEncoding,
31               charset, size, limitSize, DiskFileUpload.baseDirectory, DiskFileUpload.deleteOnExitTemporaryFile);
32      }
33  
34      public MixedFileUpload(String name, String filename, String contentType,
35                             String contentTransferEncoding, Charset charset, long size,
36                             long limitSize, String baseDir, boolean deleteOnExit) {
37          super(limitSize, baseDir, deleteOnExit,
38                size > limitSize?
39                        new DiskFileUpload(name, filename, contentType, contentTransferEncoding, charset, size, baseDir,
40                                           deleteOnExit) :
41                        new MemoryFileUpload(name, filename, contentType, contentTransferEncoding, charset, size)
42          );
43      }
44  
45      @Override
46      public String getContentTransferEncoding() {
47          return wrapped.getContentTransferEncoding();
48      }
49  
50      @Override
51      public String getFilename() {
52          return wrapped.getFilename();
53      }
54  
55      @Override
56      public void setContentTransferEncoding(String contentTransferEncoding) {
57          wrapped.setContentTransferEncoding(contentTransferEncoding);
58      }
59  
60      @Override
61      public void setFilename(String filename) {
62          wrapped.setFilename(filename);
63      }
64  
65      @Override
66      public void setContentType(String contentType) {
67          wrapped.setContentType(contentType);
68      }
69  
70      @Override
71      public String getContentType() {
72          return wrapped.getContentType();
73      }
74  
75      @Override
76      FileUpload makeDiskData() {
77          DiskFileUpload diskFileUpload = new DiskFileUpload(
78                  getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), definedLength(),
79                  baseDir, deleteOnExit);
80          diskFileUpload.setMaxSize(getMaxSize());
81          return diskFileUpload;
82      }
83  
84      @Override
85      public FileUpload copy() {
86          // for binary compatibility
87          return super.copy();
88      }
89  
90      @Override
91      public FileUpload duplicate() {
92          // for binary compatibility
93          return super.duplicate();
94      }
95  
96      @Override
97      public FileUpload retainedDuplicate() {
98          // for binary compatibility
99          return super.retainedDuplicate();
100     }
101 
102     @Override
103     public FileUpload replace(ByteBuf content) {
104         // for binary compatibility
105         return super.replace(content);
106     }
107 
108     @Override
109     public FileUpload touch() {
110         // for binary compatibility
111         return super.touch();
112     }
113 
114     @Override
115     public FileUpload touch(Object hint) {
116         // for binary compatibility
117         return super.touch(hint);
118     }
119 
120     @Override
121     public FileUpload retain() {
122         // for binary compatibility
123         return super.retain();
124     }
125 
126     @Override
127     public FileUpload retain(int increment) {
128         // for binary compatibility
129         return super.retain(increment);
130     }
131 }