简体   繁体   English

如何为使用Java上传文件创建代理服务器?

[英]How to create a proxy server for files uploading using Java?

I have to create a proxy for file uploading but the problem is that I don't have to store an entire file on the proxy server. 我必须创建用于文件上传的代理,但是问题是我不必在代理服务器上存储整个文件。 My proxy have to accept very big files (files with size up to 80 GB) and store an entire file in the object storage (openstack swift). 我的代理必须接受非常大的文件(文件大小最大为80 GB),并将整个文件存储在对象存储中(openstack swift)。 But proxy don't have to keep an entire file in the RAM or on the disk. 但是代理不必将整个文件保留在RAM或磁盘中。 Proxy have to act like a pipe. 代理必须像管道一样行事。
How to create such system? 如何建立这样的系统?

Simple create a server socket to accept the requests and for each request received, open an output stream to the target (filesystem, database, cloud storage, ...). 简单创建一个服务器套接字以接受请求,并为收到的每个请求打开到目标(文件系统,数据库,云存储等)的输出流。 Then do a loop which reads a chuck of bytes, eg 4K bytes, from the input stream and then write those 4K bytes to the output stream. 然后执行一个循环,从输入流中读取一个字节的块,例如4K字节,然后将那些4K字节写入输出流。 Continue this, until there are no more bytes to read from the input. 继续此操作,直到没有更多字节可从输入读取。 Close the input stream and flush and close the output stream. 关闭输入流,然后刷新并关闭输出流。 See here for an example 参见这里的例子

Connecting an input stream to an outputstream 将输入流连接到输出流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM