本文整理汇总了Java中io.vertx.core.http.HttpServerFileUpload类的典型用法代码示例。如果您正苦于以下问题:Java HttpServerFileUpload类的具体用法?Java HttpServerFileUpload怎么用?Java HttpServerFileUpload使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpServerFileUpload类属于io.vertx.core.http包,在下文中一共展示了HttpServerFileUpload类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tempFile
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
/**
* Creates a temporary file.
*
* @return a new Temp File from getDiskFilename(), default prefix, postfix and baseDirectory
*/
static synchronized File tempFile(HttpServerFileUpload upload) {
String newpostfix;
String diskFilename = new File(upload.filename()).getName();
newpostfix = '_' + diskFilename;
File tmpFile;
try {
if (baseDirectory == null) {
// create a temporary file
tmpFile = File.createTempFile(prefix, newpostfix);
} else {
tmpFile = File.createTempFile(prefix, newpostfix, new File(
baseDirectory));
}
if (deleteOnExitTemporaryFile) {
tmpFile.deleteOnExit();
}
return tmpFile;
} catch (IOException e) {
// Really bad, can't create the tmp file.
throw new IllegalStateException(e);
}
}
示例2: put
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
/**
* Uploads the file contents to S3.
*
* @param aBucket An S3 bucket
* @param aKey An S3 key
* @param aUpload An HttpServerFileUpload
* @param aHandler An upload response handler
*/
public void put(final String aBucket, final String aKey, final HttpServerFileUpload aUpload,
final Handler<HttpClientResponse> aHandler) {
final S3ClientRequest request = createPutRequest(aBucket, aKey, aHandler);
final Buffer buffer = Buffer.buffer();
aUpload.endHandler(event -> {
request.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length()));
request.end(buffer);
});
aUpload.handler(data -> {
buffer.appendBuffer(data);
});
}
示例3: MixedFileUpload
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
/**
* Creates an instance of {@link org.wisdom.framework.vertx.file.VertxFileUpload}.
*
* @param vertx the Vert.X instance
* @param upload the upload object
* @param limitSize the threshold. If the amount of uploaded data is below this limit,
* {@link org.wisdom.framework.vertx.file.MemoryFileUpload} is used to backend the uploaded file.
* Otherwise, it uses a {@link org.wisdom.framework.vertx.file.DiskFileUpload}.
*/
public MixedFileUpload(final Vertx vertx,
final HttpServerFileUpload upload,
final long limitSize,
final long maxSize,
final Handler<Result> errorHandler) {
super(upload, errorHandler);
delegate = new MemoryFileUpload(upload, errorHandler);
upload.exceptionHandler(event -> LoggerFactory.getLogger(MixedFileUpload.class)
.error("Cannot read the uploaded item {} ({})", upload.name(), upload.filename(), event))
.endHandler(event -> delegate.close())
.handler(
event -> {
if (event != null) {
// We are still in memory.
if (delegate instanceof MemoryFileUpload) {
MemoryFileUpload mem = (MemoryFileUpload) delegate;
checkSize(mem.buffer.length() + event.length(), maxSize, upload);
if (mem.buffer.length() + event.length() > limitSize) {
// Switch to disk file upload.
DiskFileUpload disk = new DiskFileUpload(vertx, upload, errorHandler);
// Initial push (mem + current buffer)
disk.push(mem.buffer.appendBuffer(event));
// No cleanup required for the memory based backend.
delegate = disk;
// the disk based implementation use a pump.
} else {
delegate.push(event);
}
}
}
}
);
}
示例4: FileUploadImpl
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
public FileUploadImpl(String uploadedFileName, HttpServerFileUpload upload) {
this.uploadedFileName = uploadedFileName;
this.upload = upload;
}
示例5: checkSize
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
/**
* Checks whether we exceed the max allowed file size.
*
* @param newSize the expected size once the current chunk is consumed
* @param maxSize the max allowed size.
* @param upload the upload
*/
private void checkSize(long newSize, long maxSize, HttpServerFileUpload upload) {
if (maxSize >= 0 && newSize > maxSize) {
upload.handler(null);
report(new IllegalStateException("Size exceed allowed maximum capacity"));
}
}
示例6: DiskFileUpload
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
/**
* Creates an instance of {@link org.wisdom.framework.vertx.file.DiskFileUpload}.
*
* @param vertx the Vert.X instance
* @param upload the Vert.X file upload object
* @param errorHandler the error handler
*/
public DiskFileUpload(Vertx vertx, HttpServerFileUpload upload, Handler<Result> errorHandler) {
super(upload, errorHandler);
this.file = tempFile(upload);
this.vertx = vertx;
}
示例7: MemoryFileUpload
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
/**
* Creates an instance of {@link org.wisdom.framework.vertx.file.MemoryFileUpload}.
*
* @param upload the Vert.X file upload object
* @param errorHandler the error handler
*/
public MemoryFileUpload(HttpServerFileUpload upload, Handler<Result> errorHandler) {
super(upload, errorHandler);
}
示例8: VertxFileUpload
import io.vertx.core.http.HttpServerFileUpload; //导入依赖的package包/类
/**
* Creates the {@link org.wisdom.framework.vertx.file.VertxFileUpload}.
*
* @param upload the {@link HttpServerFileUpload} that is uploaded.
* @param errorHandler the error handler.
*/
protected VertxFileUpload(HttpServerFileUpload upload, Handler<Result> errorHandler) {
this.upload = upload;
this.errorHandler = errorHandler;
}