Reading multiple XML files from an input stream Java -


how read multiple xml files input stream in java , write them xml files?

i have this:

inputstream = new gzipinputstream(new fileinputstream(file)); 

edit: have tar.gz file say, xmls.tar.gz "file" contains multiple xml files. when convert string using:

public static string convertstreamtostring(java.io.inputstream is) {         java.util.scanner s = new java.util.scanner(is).usedelimiter("\\a");         return s.hasnext() ? s.next() : "";     } 

i of xml files chained together, file information well. on system.out.println get(this beginning of 1 file):

blah.xml    60      0      0        2300 12077203627  10436 0ustar     0      0 <?xml version="1.0"... 

answer:

this worked great me, following on keith's suggestion use apache compress , io:

http://thinktibits.blogspot.com/2013/01/read-extract-tar-file-java-example.html

import java.io.*; import org.apache.commons.compress.archivers.tar.tararchiveentry; import org.apache.commons.compress.archivers.tar.tararchiveinputstream; import org.apache.commons.io.ioutils; public class untar {           public static void main(string[] args) throws exception{                 /* read tar file tararchiveinputstream */                 tararchiveinputstream mytarfile=new tararchiveinputstream(new fileinputstream(new file("tar_ball.tar")));                 /* read individual tar file */                 tararchiveentry entry = null;                 string individualfiles;                 int offset;                 fileoutputstream outputfile=null;                 /* create loop read every single entry in tar file */                 while ((entry = mytarfile.getnexttarentry()) != null) {                         /* name of file */                         individualfiles = entry.getname();                         /* size of file , create byte array size */                         byte[] content = new byte[(int) entry.getsize()];                         offset=0;                         /* sop statements check progress */                         system.out.println("file name in tar file is: " + individualfiles);                         system.out.println("size of file is: " + entry.getsize());                                           system.out.println("byte array length: " + content.length);                         /* read file archive byte array */                         mytarfile.read(content, offset, content.length - offset);                         /* define outputstream writing file */                         outputfile=new fileoutputstream(new file(individualfiles));                         /* use ioutiles write content of byte array physical file */                         ioutils.write(content,outputfile);                                       /* close output stream */                         outputfile.close();                 }                                /* close tarachiveinputstream */                 mytarfile.close();         } } 

after un-compressing (gzip) still need un-tar. java jdk doesn't have built in api tar, there several available third parties. see answer: how extract tar file in java?


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -