public MixedAttribute(String name, String value, long limitSize, Charset charset) { this.limitSize = limitSize; if (value.length() > this.limitSize) { try { attribute = new DiskAttribute(name, value, charset); } catch (IOException e) { // revert to Memory mode try { attribute = new MemoryAttribute(name, value, charset); } catch (IOException ignore) { throw new IllegalArgumentException(e); } } } else { try { attribute = new MemoryAttribute(name, value, charset); } catch (IOException e) { throw new IllegalArgumentException(e); } } }
@Override public void setContent(File file) throws IOException { checkSize(file.length()); if (file.length() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(file); }
@Override public void setContent(ByteBuf buffer) throws IOException { checkSize(buffer.readableBytes()); if (buffer.readableBytes() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(buffer); }
@Override public void setContent(InputStream inputStream) throws IOException { if (attribute instanceof MemoryAttribute) { // change to Disk even if we don't know the size attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } attribute.setContent(inputStream); }
@Override public Attribute createAttribute(HttpRequest request, String name) { if (useDisk) { Attribute attribute = new DiskAttribute(name, charset); attribute.setMaxSize(maxSize); List<HttpData> list = getList(request); list.add(attribute); return attribute; } if (checkSize) { Attribute attribute = new MixedAttribute(name, minSize, charset); attribute.setMaxSize(maxSize); List<HttpData> list = getList(request); list.add(attribute); return attribute; } MemoryAttribute attribute = new MemoryAttribute(name); attribute.setMaxSize(maxSize); return attribute; }
@Override public Attribute createAttribute(HttpRequest request, String name, long definedSize) { if (useDisk) { Attribute attribute = new DiskAttribute(name, definedSize, charset); attribute.setMaxSize(maxSize); List<HttpData> list = getList(request); list.add(attribute); return attribute; } if (checkSize) { Attribute attribute = new MixedAttribute(name, definedSize, minSize, charset); attribute.setMaxSize(maxSize); List<HttpData> list = getList(request); list.add(attribute); return attribute; } MemoryAttribute attribute = new MemoryAttribute(name, definedSize); attribute.setMaxSize(maxSize); return attribute; }
@Override public Attribute replace(ByteBuf content) { DiskAttribute attr = new DiskAttribute(getName()); attr.setCharset(getCharset()); if (content != null) { try { attr.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return attr; }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (attribute instanceof MemoryAttribute) { checkSize(attribute.length() + buffer.readableBytes()); if (attribute.length() + buffer.readableBytes() > limitSize) { DiskAttribute diskAttribute = new DiskAttribute(attribute .getName(), attribute.definedLength()); diskAttribute.setMaxSize(maxSize); if (((MemoryAttribute) attribute).getByteBuf() != null) { diskAttribute.addContent(((MemoryAttribute) attribute) .getByteBuf(), false); } attribute = diskAttribute; } } attribute.addContent(buffer, last); }
Attribute attribute; try { attribute = new DiskAttribute(name, value, charset); attribute.setMaxSize(maxSize); } catch (IOException e) {
@Override public void setContent(File file) throws IOException { checkSize(file.length()); if (file.length() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(file); }
@Override public void setContent(ByteBuf buffer) throws IOException { checkSize(buffer.readableBytes()); if (buffer.readableBytes() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(buffer); }
@Override public void setContent(File file) throws IOException { checkSize(file.length()); if (file.length() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(file); }
@Override public void setContent(ByteBuf buffer) throws IOException { checkSize(buffer.readableBytes()); if (buffer.readableBytes() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(buffer); }
@Override public void setContent(File file) throws IOException { checkSize(file.length()); if (file.length() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(file); }
@Override public void setContent(File file) throws IOException { checkSize(file.length()); if (file.length() > limitSize) { if (attribute instanceof MemoryAttribute) { // change to Disk attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } } attribute.setContent(file); }
@Override public void setContent(InputStream inputStream) throws IOException { if (attribute instanceof MemoryAttribute) { // change to Disk even if we don't know the size attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } attribute.setContent(inputStream); }
@Override public void setContent(InputStream inputStream) throws IOException { if (attribute instanceof MemoryAttribute) { // change to Disk even if we don't know the size attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } attribute.setContent(inputStream); }
@Override public void setContent(InputStream inputStream) throws IOException { if (attribute instanceof MemoryAttribute) { // change to Disk even if we don't know the size attribute = new DiskAttribute(attribute.getName(), attribute.definedLength()); attribute.setMaxSize(maxSize); } attribute.setContent(inputStream); }
@Override public Attribute replace(ByteBuf content) { DiskAttribute attr = new DiskAttribute(getName()); attr.setCharset(getCharset()); if (content != null) { try { attr.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return attr; }
@Override public Attribute replace(ByteBuf content) { DiskAttribute attr = new DiskAttribute(getName()); attr.setCharset(getCharset()); if (content != null) { try { attr.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return attr; }