我正在使用 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