Jets3t zipfile上传,流自动关闭

时间:2013-02-17 17:10:15

标签: java spring grails groovy jets3t

我正在通过多部分网络表格上传压缩文件。我使用groovy和grails进行上传,但代码看起来与Java(使用spring)类似......

def processUpload(){
    def uploadedFile = request.getFile('payload')
    String vloc = "";
    String filename = ""

    if(!uploadedFile.empty){
        InputStream is = uploadedFile.getInputStream()
        java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(is)
        def zipentry = zis.getNextEntry();
        while(zipentry!=null){
            println zipentry.getName()
            if( zipentry.getName().indexOf(".")>0){
                amazonS3Service.put (zis, zipentry.getName(), session.uid, ".zyx", zipentry.getSize())
            }
            zipentry = zis.getNextEntry()
        }           
    }
}

amazonS3Service.put如下

String put(inputstream, name, uid, ext, length)
{
    String mime = mimeExtensionMap[ext.toLowerCase()]
    S3Bucket bucket = makeBucket(uid)
    S3Object s3Obj = new S3Object()
    s3Obj.setAcl AccessControlList.REST_CANNED_PRIVATE
    s3Obj.setContentLength length
    s3Obj.setContentType mime
    s3Obj.setDataInputStream inputstream
    s3Obj.setKey name
    s3Obj.setBucketName bucket.getName()
    s3.putObject bucket, s3Obj
    return name
}

似乎s3.putObject bucket,s3Obj方法正在关闭我的流,因为我收到streamClosed异常。我需要从zipfile中获取nextentry,因此不应该关闭流!

我曾尝试将byteArrayinputstream与zis.getBytes()一起使用,但即使getBytes()关闭了流!!

我有什么选择?

由于

0 个答案:

没有答案