我正在使用netty 3.5.0并且我已经实现了上传示例HttpUploadServer
,HttpUploadServerHandler
,HttpUploaderServerPipeLineFactory
。
在HttpUploadServerHandler
中,有一些注释掉的行
// fileUpload.isInMemory();// tells if the file is in Memory
// or on File
// fileUpload.renameTo(dest); // enable to move into another
// File dest
// decoder.removeFileUploadFromClean(fileUpload); //remove
// the File of to delete file
当我在这些行中评论时,特别是renameTo(dest)
,我发现它在大文件传输中间歇性地失败,下面会出现内存不足的错误。
除此之外:removeFileUploadFromClean
似乎无法解决
谁能告诉我发生了什么或如何解决?
我希望能够传输大文件,然后将它们从临时位置移动到最终目的地。当你不使用renameTo
时,转移到临时位置似乎非常好,但是由于我认为清理后文件很快被删除。
HttpUploadServerHandler::messageReceived
HttpUploadServerHandler::messageReceived
HttpUploadServerHandler::messageReceived
HttpUploadServerHandler::messageReceived
renaming fileoxygen.exe
fileUpload.getFilename() oxygen.exe
fileUpload.getName() myfile
java.io.IOException: Map failed
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:748)
at sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:437)
at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:510)
at org.jboss.netty.handler.codec.http.multipart.AbstractDiskHttpData.renameTo(AbstractDiskHttpData.java:292)
at org.jboss.netty.handler.codec.http.multipart.MixedFileUpload.renameTo(MixedFileUpload.java:117)
at com.vayyoo.vaf.nettyapp.upload.HttpUploadServerHandler.writeHttpData(HttpUploadServerHandler.java:317)
at com.vayyoo.vaf.nettyapp.upload.HttpUploadServerHandler.readHttpDataChunkByChunk(HttpUploadServerHandler.java:253)
at com.vayyoo.vaf.nettyapp.upload.HttpUploadServerHandler.messageReceived(HttpUploadServerHandler.java:208)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.codec.http.HttpContentEncoder.messageReceived(HttpContentEncoder.java:67)
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:95)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:359)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:568)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:437)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:91)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:373)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:247)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.OutOfMemoryError: Map failed
at sun.nio.ch.FileChannelImpl.map0(Native Method)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:745)
renamed file to c:\temp\oxygen.exe
HttpUploadServerHandler::messageReceived
renaming fileoxygen.exe
fileUpload.getFilename() oxygen.exe
fileUpload.getName() myfile
... 32 more
java.io.IOException: Map failed
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:748)
at sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:437)
at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:510)
at org.jboss.netty.handler.codec.http.multipart.AbstractDiskHttpData.renameTo(AbstractDiskHttpData.java:292)
at org.jboss.netty.handler.codec.http.multipart.MixedFileUpload.renameTo(MixedFileUpload.java:117)
at com.vayyoo.vaf.nettyapp.upload.HttpUploadServerHandler.writeHttpData(HttpUploadServerHandler.java:317)
at com.vayyoo.vaf.nettyapp.upload.HttpUploadServerHandler.readHttpDataAllReceive(HttpUploadServerHandler.java:236)
at com.vayyoo.vaf.nettyapp.upload.HttpUploadServerHandler.messageReceived(HttpUploadServerHandler.java:211)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.codec.http.HttpContentEncoder.messageReceived(HttpContentEncoder.java:67)
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:95)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:359)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:568)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:437)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:91)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:373)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:247)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.OutOfMemoryError: Map failed
at sun.nio.ch.FileChannelImpl.map0(Native Method)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:745)
... 32 more
renamed file to c:\temp\oxygen.exe
HttpUploadServerHandler::messageReceived
答案 0 :(得分:0)
对我来说,renameTo()
的目的地与临时文件不属于同一个文件系统。因此,尝试移动文件失败,renameTo()
将文件复制到目标并删除临时文件。但是,似乎renameTo()
以奇怪的方式实现了文件复制操作。 (即bug)。在修复错误之前,您可以:
您可以在此处跟踪此问题:https://github.com/netty/netty/issues/398
答案 1 :(得分:0)
您提出的问题将在版本3.5.1.Final修复。