问题描述
我有一个Base64-CN $ C与下面的头$ CD对象:
I have a Base64-encoded object with the following header:
application/x-xfdl;content-encoding="asc-gzip"
什么是对象解码进行的最佳方式?我是否需要剥离的第一线?另外,如果我把它变成一个字节数组(字节[]),我怎么取消gzip压缩吗?
What is the best way to proceed in decoding the object? Do I need to strip the first line? Also, if I turn it into a byte array (byte[]), how do I un-gzip it?
谢谢!
我想我最初说错。说头是
I think I misspoke initially. By saying the header was
application/x-xfdl;content-encoding="asc-gzip"
我的意思,这是该文件的第一行。因此,为了使用Java或C#库去code中的文件,做这一行需要被剥离?
I meant this was the first line of the file. So, in order to use the Java or C# libraries to decode the file, does this line need to be stripped?
如果是这样,这将是剥离的第一行最简单的方法?
If so, what would be the simplest way to strip the first line?
推荐答案
我可以使用下面的code到.xfdl文档转换为Java DOM文档。
I was able to use the following code to convert an .xfdl document into a Java DOM Document.
我用 Base64的实用程序执行的Base64德code。
I used iHarder's Base64 utility to do the Base64 Decode.
private static final String FILE_HEADER_BLOCK =
"application/vnd.xfdl;content-encoding=\"base64-gzip\"";
public static Document OpenXFDL(String inputFile)
throws IOException,
ParserConfigurationException,
SAXException
{
try{
//create file object
File f = new File(inputFile);
if(!f.exists()) {
throw new IOException("Specified File could not be found!");
}
//open file stream from file
FileInputStream fis = new FileInputStream(inputFile);
//Skip past the MIME header
fis.skip(FILE_HEADER_BLOCK.length());
//Decompress from base 64
Base64.InputStream bis = new Base64.InputStream(fis,
Base64.DECODE);
//UnZIP the resulting stream
GZIPInputStream gis = new GZIPInputStream(bis);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(gis);
gis.close();
bis.close();
fis.close();
return doc;
}
catch (ParserConfigurationException pce) {
throw new ParserConfigurationException("Error parsing XFDL from file.");
}
catch (SAXException saxe) {
throw new SAXException("Error parsing XFDL into XML Document.");
}
}
仍在努力成功地修改和重新编码的文件。
Still working on successfully modifying and re-encoding the document.
希望这有助于。
这篇关于Base64编码德code在C#或Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!