Fix in addContent when switching from MemoryAttribute if it is done when

last buffer added, in order to not close immediately the underlying
file before adding the last buffer.

- Contribution by @fredericBregier
This commit is contained in:
Trustin Lee 2012-05-30 17:28:51 -07:00
parent dba9a6d408
commit e8bc276ddd
2 changed files with 9 additions and 9 deletions

View File

@ -15,20 +15,20 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ChannelBuffer;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import io.netty.buffer.ChannelBuffer;
/** /**
* Mixed implementation using both in Memory and in File with a limit of size * Mixed implementation using both in Memory and in File with a limit of size
*/ */
public class MixedAttribute implements Attribute { public class MixedAttribute implements Attribute {
private Attribute attribute; private Attribute attribute;
private long limitSize; private final long limitSize;
public MixedAttribute(String name, long limitSize) { public MixedAttribute(String name, long limitSize) {
this.limitSize = limitSize; this.limitSize = limitSize;
@ -65,7 +65,7 @@ public class MixedAttribute implements Attribute {
.getName()); .getName());
if (((MemoryAttribute) attribute).getChannelBuffer() != null) { if (((MemoryAttribute) attribute).getChannelBuffer() != null) {
diskAttribute.addContent(((MemoryAttribute) attribute) diskAttribute.addContent(((MemoryAttribute) attribute)
.getChannelBuffer(), last); .getChannelBuffer(), false);
} }
attribute = diskAttribute; attribute = diskAttribute;
} }

View File

@ -15,22 +15,22 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ChannelBuffer;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import io.netty.buffer.ChannelBuffer;
/** /**
* Mixed implementation using both in Memory and in File with a limit of size * Mixed implementation using both in Memory and in File with a limit of size
*/ */
public class MixedFileUpload implements FileUpload { public class MixedFileUpload implements FileUpload {
private FileUpload fileUpload; private FileUpload fileUpload;
private long limitSize; private final long limitSize;
private long definedSize; private final long definedSize;
public MixedFileUpload(String name, String filename, String contentType, public MixedFileUpload(String name, String filename, String contentType,
String contentTransferEncoding, Charset charset, long size, String contentTransferEncoding, Charset charset, long size,
@ -58,7 +58,7 @@ public class MixedFileUpload implements FileUpload {
definedSize); definedSize);
if (((MemoryFileUpload) fileUpload).getChannelBuffer() != null) { if (((MemoryFileUpload) fileUpload).getChannelBuffer() != null) {
diskFileUpload.addContent(((MemoryFileUpload) fileUpload) diskFileUpload.addContent(((MemoryFileUpload) fileUpload)
.getChannelBuffer(), last); .getChannelBuffer(), false);
} }
fileUpload = diskFileUpload; fileUpload = diskFileUpload;
} }