Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.io.IOException:传入ByteArrayInputStream时不是GZIP格式_Java_Jaxb_Gzipinputstream - Fatal编程技术网

java.io.IOException:传入ByteArrayInputStream时不是GZIP格式

java.io.IOException:传入ByteArrayInputStream时不是GZIP格式,java,jaxb,gzipinputstream,Java,Jaxb,Gzipinputstream,persistenceService.put看起来像 final ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { jaxbContext.createMarshaller().marshal(proposal, stream); try { stream.close();

persistenceService.put
看起来像

        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            jaxbContext.createMarshaller().marshal(proposal, stream);
            try {
                    stream.close();
            } catch (IOException e) {
                throw new PersistenceException("Failed to close output stream for " + proposal.getUniqueId());
            }
            // call persistenceService.put to send data to respective PersistenceServiceClass
            InputStream inputStream = new ByteArrayInputStream(stream.toByteArray());
            persistenceService.put(inputStream, proposal.getUniqueId());
当我运行这段代码时,我看到下面的stacktrace

public void put(@Nonnull final InputStream inputStream, @Nonnull final String uniqueId) throws PersistenceException {
        // a.) create xml.zip of inputStream as inputStream
        final GZIPInputStream zipInputStream;
        try {
            zipInputStream = new GZIPInputStream(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
            throw new PersistenceException("Persistence Service could not received input stream to persist for " + uniqueId);
        }

        // b.) call amazonS3client.putObject() to put data
        final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, getProposalName(uniqueId), zipInputStream, new ObjectMetadata());
    }
java.io.IOException:不是GZIP格式
位于java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:141)
位于java.util.zip.GZIPInputStream。(GZIPInputStream.java:56)
位于java.util.zip.GZIPInputStream。(GZIPInputStream.java:65)
位于com.sunrunhome.sparrow.business.xml.persist.S3Service.put(S3Service.java:71)
位于com.sunrunhome.sparrow.business.ProposalManager.putDocument(ProposalManager.java:56)
位于com.sunrunhome.sparrow.business.ProposalManager.testWriteToS3(ProposalManager.java:165)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)中
位于java.lang.reflect.Method.invoke(Method.java:597)
位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:45)
位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:42)
位于org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
位于org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
位于org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
位于org.junit.rules.RunRules.evaluate(RunRules.java:18)
我没有在这里做什么

java.io.IOException: Not in GZIP format
    at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:141)
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:56)
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:65)
    at com.sunrunhome.sparrow.business.xml.persist.S3Service.put(S3Service.java:71)
    at com.sunrunhome.sparrow.business.ProposalManager.putDocument(ProposalManager.java:56)
    at com.sunrunhome.sparrow.business.ProposalManagerTest.testWriteToS3(ProposalManagerTest.java:165)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
    at org.junit.rules.RunRules.evaluate(RunRules.java:18)

您可以将其作为
fileInputStream
传递并测试它

您正在将一组非gzip字节传递给gzip解压器。
private static void gzip(File file) {
    //logic to extract file
    GZIPInputStream in = null;
    FileInputStream fin = null;
    OutputStream out = null;
    int noread = 0;

    try {
        in = new GZIPInputStream(new FileInputStream(file));
        extractedFile = new File("C:\\DATA\\extracted.txt");
        out = new FileOutputStream(extractedFile);
        byte[] buffer = new byte[65536];
        noread = in.read(buffer);

        while(noread > 0) {
            out.write(buffer, 0, noread);
            System.out.println("done");
            break;
        }
    }