How to convert ArchiveEntry to InputStream?

membersound

I'm reading a tar.gz archive using

ArchiveEntry entry = tarArchiveInputStream.getNextEntry();

Question: how can I convert this ArchiveEntry to an InputStream so I can actually read and process the file to a String?

Sami Nurminen

You could use IOUtils to read InputStream fully:

import org.apache.commons.compress.utils.IOUtils

byte[] buf = new byte[(int) entry.getSize()];
int readed  = IOUtils.readFully(tarArchiveInputStream,buf);

//readed should equal buffer size
if(readed != buf.length) {
 throw new RuntimeException("Read bytes count and entry size differ");
}

String string = new String(buf, StandardCharsets.UTF_8);

If your file is in other encoding than utf-8, use that instead of utf-8 in the constructor of string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert InputStream to FileInputStream

How to convert BufferedImage to InputStream?

How to convert OutputStream to InputStream?

How to convert InputStream into Source?

How to convert FileInputStream to InputStream?

How to convert an InputStream to a DataHandler?

How to convert InputStream to int

How to convert InputStream to virtual File

How to convert Reader to InputStream in java

How to convert a String to an InputStream in Kotlin?

How can I convert an uncompressed InputStream into a gzip'ed InputStream efficiently?

How to convert the response from Okhttp into inputstream

How can I convert ZipInputStream to InputStream?

How to convert StringBuffer to InputStream in Java ME?

How to convert Source[ByteString, Any] to InputStream

How do I convert an InputStream to a String in Java?

How do I convert a String to an InputStream in Java?

How to convert a Reader to InputStream and a Writer to OutputStream?

How can I convert an Object to Inputstream

How to convert InputStream to Json in Camel K

How to convert a PDF InputStream to an Html String?

How to convert an InputStream object to a File object?

How to convert Reactor Flux<String> to InputStream

How to convert Outlook.MailItem attachment to inputstream?

How to correctly read Flux<DataBuffer> and convert it to a single inputStream

How do I convert a InputStream to BufferedImage in Java/Groovy?

How do I read / convert an InputStream into a String in Java?

How to convert javax.xml.transform.Source into an InputStream?

How to convert org.jruby.RubyString to java.io.InputStream