[英]Different size between original and cloned file(java)
am cloning xml file in my java code in a such way: 我以这种方式在我的Java代码中克隆xml文件:
public boolean isCrcCorrect(Path path) throws IOException, XPathExpressionException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
if (!fileData.currentFilePath.equals(path.toString())) {
parseFile(path);
}
List<String> file_lines = Files.readAllLines(path);
//BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(output));
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("f:\\Projects\\iqpdct\\iqpdct-domain\\src\\main\\java\\de\\iq2dev\\domain\\util\\debug.xml")));
for (int i = 0; i < file_lines.size(); i++) {
if (i != 0) {
bw.write("\n");
}
if (file_lines.get(i).equals(" <Stamp crc=\"3916602279\"><Checker name=\"IODD-Checker V1.1.1\" version=\"V1.1.1.0\"/></Stamp>")) {
bw.write(" <Stamp crc=\"\"><Checker name=\"IODD-Checker V1.1.1\" version=\"V1.1.1.0\"/></Stamp>");
} else {
bw.write(file_lines.get(i));
}
System.out.println(file_lines.get(i));
}
bw.flush();
bw.close();
crc.reset();
crc.update(output.toByteArray());
//debug
System.out.println(crc.getValue());
System.out.println(fileData.file_crc);
//return fileData.file_crc == crc.getValue();
return false;
}
I need to modiy attribute in xml (for debug I manualy made it in cycle). 我需要在xml中修改属性(为进行调试,我手动使其在循环中进行)。 I required this clone for checksum calculating. 我需要此克隆进行校验和计算。 Result file "debug.xml" is identical to source (InteliJ IDEA told so), but size is different : source: 41395, clone:40608 , so consequently I have incorrect checksum (CRC32 function) 结果文件“ debug.xml”与源文件相同(InteliJ IDEA表示),但大小不同 : 源文件:41395,clone:40608 ,因此我的校验和不正确(CRC32函数)
What can causes this? 是什么原因造成的?
Just a guess, but you seem to hardcode new lines as \\n
. 只是一个猜测,但是您似乎将新行硬编码为\\n
。 Would it be possible that your input file has Windows style line endings and you are modifying them with your code ? 输入文件是否可能具有Windows样式行的结尾并且您正在使用代码对其进行修改?
Not sure here...but when you are replacing the line <Stamp crc=\\"3916602279\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp>
with <Stamp crc=\\"\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp>
, perhaps that is causing the difference? 不确定这里...但是当您替换行<Stamp crc=\\"3916602279\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp>
与<Stamp crc=\\"\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp>
,可能是导致区别?
Just try not doing that and see if it produces the same sized clone file. 只是尝试不这样做,看看它是否生成相同大小的克隆文件。 Try that for me please. 请为我尝试一下。
Moreover, as Guillaume said, does the difference in \\n
for windows and mac have different sizes? 而且,正如Guillaume所说,Windows和Mac的\\n
的差异是否具有不同的大小?
In a completely different context, somebody correct me if I am wrong, but doesn't bw.close()
automatically call bw.flush()
? 在完全不同的上下文中,如果我错了,有人会纠正我,但是bw.close()
不会自动调用bw.flush()
吗? I thought it does. 我认为是的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.