2014-12-18 2 views
0

blobstore를 사용하여 MP3 파일을 업로드하려고합니다. 그러나 문제는 크기가 2 또는 3MB 이상인 파일을 업로드 할 때입니다. Closeable를 닫는 동안 throw되는 IOException을 던집니다. 그것은 어떤 fuctionality든지에 진짜로 영향을 미치지 않는다. 하지만 아무도 내가이 예외가 무엇인지 찾을 수 있습니까 ??Google 앱 엔진 : 닫을 때 IOException이 발생합니다. 닫을 수 있음

아래에 예외 세부 정보가 추가됩니다.

com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98) 
     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
     at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491) 
     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
     at org.mortbay.jetty.Server.handle(Server.java:326) 
     at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
     at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) 
     at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547) 
     at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) 
     at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
     at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) 
     at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 
    Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host 
     at sun.nio.ch.SocketDispatcher.write0(Native Method) 
     at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51) 
     at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) 
     at sun.nio.ch.IOUtil.write(IOUtil.java:51) 
     at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:487) 
     at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:169) 
     at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:221) 
     at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:721) 
     ... 31 more 

답변

0

나는 그것을 얻었다. 내 코드를 아래에 추가합니다.

public void getUploaded(@PathVariable String key, HttpServletRequest req, HttpServletResponse res, HttpSession session) throws IOException { 
     try { 
      BlobKey blobKey = new BlobKey(key); 
      BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey); 
      OutputStream output = res.getOutputStream(); 

      InputStream is = new ByteArrayInputStream(readData(blobKey,blobInfo.getSize())); 

      byte[] buffer = new byte[1024]; 
      int length; 
      while ((length = is.read(buffer)) > 0) 
       output.write(buffer, 0, length); 
      is.close(); 
      output.flush(); 
      output.close(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public byte[] readData(BlobKey blobKey, long blobSize) { 
     BlobstoreService blobStoreService = BlobstoreServiceFactory 
       .getBlobstoreService(); 
     byte[] allTheBytes = new byte[0]; 
     long amountLeftToRead = blobSize; 
     long startIndex = 0; 
     while (amountLeftToRead > 0) { 
      long amountToReadNow = Math.min(
        BlobstoreService.MAX_BLOB_FETCH_SIZE - 1, amountLeftToRead); 

      byte[] chunkOfBytes = blobStoreService.fetchData(blobKey, 
        startIndex, startIndex + amountToReadNow - 1); 

      allTheBytes = ArrayUtils.addAll(allTheBytes, chunkOfBytes); 

      amountLeftToRead -= amountToReadNow; 
      startIndex += amountToReadNow; 
     } 

     return allTheBytes; 
    } 
관련 문제