@Override public Attribute replace(ByteBuf content) { MemoryAttribute attr = new MemoryAttribute(getName()); attr.setCharset(getCharset()); if (content != null) { try { attr.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return attr; }
@Override public void setValue(String value) throws IOException { if (value == null) { throw new NullPointerException("value"); } byte [] bytes = value.getBytes(getCharset()); checkSize(bytes.length); ByteBuf buffer = wrappedBuffer(bytes); if (definedSize > 0) { definedSize = buffer.readableBytes(); } setContent(buffer); }
@Override public String getValue() { return getByteBuf().toString(getCharset()); }
@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 int hashCode() { return getName().hashCode(); }
@Override public int compareTo(InterfaceHttpData other) { if (!(other instanceof Attribute)) { throw new ClassCastException("Cannot compare " + getHttpDataType() + " with " + other.getHttpDataType()); } return compareTo((Attribute) other); }
public MixedAttribute(String name, long limitSize, Charset charset) { this.limitSize = limitSize; attribute = new MemoryAttribute(name, charset); }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { int localsize = buffer.readableBytes(); checkSize(size + localsize); if (definedSize > 0 && definedSize < size + localsize) { definedSize = size + localsize; } super.addContent(buffer, last); }
@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); }
@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 boolean equals(Object o) { if (!(o instanceof Attribute)) { return false; } Attribute attribute = (Attribute) o; return getName().equalsIgnoreCase(attribute.getName()); }
@Override public int compareTo(InterfaceHttpData other) { if (!(other instanceof Attribute)) { throw new ClassCastException("Cannot compare " + getHttpDataType() + " with " + other.getHttpDataType()); } return compareTo((Attribute) other); }
@Override public String getValue() { return getByteBuf().toString(getCharset()); }
public MixedAttribute(String name, long definedSize, long limitSize, Charset charset) { this.limitSize = limitSize; attribute = new MemoryAttribute(name, definedSize, charset); }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { int localsize = buffer.readableBytes(); checkSize(size + localsize); if (definedSize > 0 && definedSize < size + localsize) { definedSize = size + localsize; } super.addContent(buffer, last); }
@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); }
@Override public Attribute replace(ByteBuf content) { MemoryAttribute attr = new MemoryAttribute(getName()); attr.setCharset(getCharset()); if (content != null) { try { attr.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return attr; }