@Override public FileUpload replace(ByteBuf content) { DiskFileUpload upload = new DiskFileUpload( getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); if (content != null) { try { upload.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return upload; }
@Override public String toString() { File file = null; try { file = getFile(); } catch (IOException e) { // Should not occur. } return HttpHeaderNames.CONTENT_DISPOSITION + ": " + HttpHeaderValues.FORM_DATA + "; " + HttpHeaderValues.NAME + "=\"" + getName() + "\"; " + HttpHeaderValues.FILENAME + "=\"" + filename + "\"\r\n" + HttpHeaderNames.CONTENT_TYPE + ": " + contentType + (getCharset() != null? "; " + HttpHeaderValues.CHARSET + '=' + getCharset().name() + "\r\n" : "\r\n") + HttpHeaderNames.CONTENT_LENGTH + ": " + length() + "\r\n" + "Completed: " + isCompleted() + "\r\nIsInMemory: " + isInMemory() + "\r\nRealFile: " + (file != null ? file.getAbsolutePath() : "null") + " DefaultDeleteAfter: " + deleteOnExitTemporaryFile; }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
public MixedFileUpload(String name, String filename, String contentType, String contentTransferEncoding, Charset charset, long size, long limitSize) { this.limitSize = limitSize; if (size > this.limitSize) { fileUpload = new DiskFileUpload(name, filename, contentType, contentTransferEncoding, charset, size); } else { fileUpload = new MemoryFileUpload(name, filename, contentType, contentTransferEncoding, charset, size); } definedSize = size; }
@Override public int compareTo(InterfaceHttpData o) { if (!(o instanceof FileUpload)) { throw new ClassCastException("Cannot compare " + getHttpDataType() + " with " + o.getHttpDataType()); } return compareTo((FileUpload) o); }
if (data instanceof DiskFileUpload) { DiskFileUpload diskFileUpload = (DiskFileUpload) data; Path tmpFile = diskFileUpload.getFile().toPath(); String uploadedFilename = diskFileUpload.getFilename(); String extension = ""; if (uploadedFilename.contains(".")) {
if (file.isCompleted()) { String name = file.getFilename(); file.renameTo(target);
@Override public void setContent(File file) throws IOException { checkSize(file.length()); if (file.length() > limitSize) { if (fileUpload instanceof MemoryFileUpload) { FileUpload memoryUpload = fileUpload; // change to Disk fileUpload = new DiskFileUpload(memoryUpload .getName(), memoryUpload.getFilename(), memoryUpload .getContentType(), memoryUpload .getContentTransferEncoding(), memoryUpload.getCharset(), definedSize); fileUpload.setMaxSize(maxSize); // release old upload memoryUpload.release(); } } fileUpload.setContent(file); }
@Override public int compareTo(InterfaceHttpData o) { if (!(o instanceof FileUpload)) { throw new ClassCastException("Cannot compare " + getHttpDataType() + " with " + o.getHttpDataType()); } return compareTo((FileUpload) o); }
@Override public FileUpload replace(ByteBuf content) { DiskFileUpload upload = new DiskFileUpload( getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); if (content != null) { try { upload.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return upload; }
@Override public String toString() { File file = null; try { file = getFile(); } catch (IOException e) { // Should not occur. } return HttpHeaderNames.CONTENT_DISPOSITION + ": " + HttpHeaderValues.FORM_DATA + "; " + HttpHeaderValues.NAME + "=\"" + getName() + "\"; " + HttpHeaderValues.FILENAME + "=\"" + filename + "\"\r\n" + HttpHeaderNames.CONTENT_TYPE + ": " + contentType + (getCharset() != null? "; " + HttpHeaderValues.CHARSET + '=' + getCharset().name() + "\r\n" : "\r\n") + HttpHeaderNames.CONTENT_LENGTH + ": " + length() + "\r\n" + "Completed: " + isCompleted() + "\r\nIsInMemory: " + isInMemory() + "\r\nRealFile: " + (file != null ? file.getAbsolutePath() : "null") + " DefaultDeleteAfter: " + deleteOnExitTemporaryFile; }
@Override public FileUpload retainedDuplicate() { ByteBuf content = content(); if (content != null) { content = content.retainedDuplicate(); boolean success = false; try { FileUpload duplicate = replace(content); success = true; return duplicate; } finally { if (!success) { content.release(); } } } else { return replace(null); } }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
@Override public void setContent(ByteBuf buffer) throws IOException { checkSize(buffer.readableBytes()); if (buffer.readableBytes() > limitSize) { if (fileUpload instanceof MemoryFileUpload) { FileUpload memoryUpload = fileUpload; // change to Disk fileUpload = new DiskFileUpload(memoryUpload .getName(), memoryUpload.getFilename(), memoryUpload .getContentType(), memoryUpload .getContentTransferEncoding(), memoryUpload.getCharset(), definedSize); fileUpload.setMaxSize(maxSize); // release old upload memoryUpload.release(); } } fileUpload.setContent(buffer); }
@Override public int compareTo(InterfaceHttpData o) { if (!(o instanceof FileUpload)) { throw new ClassCastException("Cannot compare " + getHttpDataType() + " with " + o.getHttpDataType()); } return compareTo((FileUpload) o); }
@Override public FileUpload replace(ByteBuf content) { DiskFileUpload upload = new DiskFileUpload( getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); if (content != null) { try { upload.setContent(content); } catch (IOException e) { throw new ChannelException(e); } } return upload; }
@Override public String toString() { File file = null; try { file = getFile(); } catch (IOException e) { // Should not occur. } return HttpHeaderNames.CONTENT_DISPOSITION + ": " + HttpHeaderValues.FORM_DATA + "; " + HttpHeaderValues.NAME + "=\"" + getName() + "\"; " + HttpHeaderValues.FILENAME + "=\"" + filename + "\"\r\n" + HttpHeaderNames.CONTENT_TYPE + ": " + contentType + (getCharset() != null? "; " + HttpHeaderValues.CHARSET + '=' + getCharset().name() + "\r\n" : "\r\n") + HttpHeaderNames.CONTENT_LENGTH + ": " + length() + "\r\n" + "Completed: " + isCompleted() + "\r\nIsInMemory: " + isInMemory() + "\r\nRealFile: " + (file != null ? file.getAbsolutePath() : "null") + " DefaultDeleteAfter: " + deleteOnExitTemporaryFile; }