问题描述
我需要从quicktime文件中读取unsigned int,然后将其写回另一个quicktime文件。
I need to read an unsigned int from a quicktime file, and write it back to another quicktime file.
目前我将unsigned int读入Long,但在写回来的时候,我从未设法用4个字节作为unsigned int写回确切的数字。长期具有我需要回写的正确值。
(例如3289763894或370500)
我甚至无法读取写入小于Integer.MAX_VALUE(例如2997)的数字。
Currently I read the unsigned int into a Long but while writing it back I never managed to write the exact number back in 4 bytes as unsigned int. The long has the correct value that I need to write back.(eg 3289763894 or 370500)I am unable to even read the write a number smaller then Integer.MAX_VALUE (eg 2997).
I我使用以下方法将值写回来
I am using the following methods to write the value back
public void writeUInt32(long uint32,DataOutputStream stream) throws IOException {
writeUInt16((int) (uint32 & 0xffff0000) >> 16,stream);
writeUInt16((int) uint32 & 0x0000ffff,stream);
}
public void writeUInt16(int uint16,DataOutputStream stream) throws IOException {
writeUInt8(uint16 >> 8, stream);
writeUInt8(uint16, stream);
}
public void writeUInt8(int uint8,DataOutputStream stream) throws IOException {
stream.write(uint8 & 0xFF);
}
任何帮助将不胜感激。
Any help would be appreciated.
推荐答案
只需将你的长期写入int。我查了一下:
Just write your long casted to int. I checked:
PipedOutputStream pipeOut = new PipedOutputStream ();
PipedInputStream pipeIn = new PipedInputStream (pipeOut);
DataOutputStream os = new DataOutputStream (pipeOut);
long uInt = 0xff1ffffdL;
System.out.println ("" + uInt + " vs " + ((int) uInt));
os.writeInt ((int) uInt);
for (int i = 0; i < 4; i++) System.out.println (pipeIn.read ());
uInt = 0x000ffffdL;
System.out.println ("" + uInt + " vs " + ((int) uInt));
os.writeInt ((int) uInt);
for (int i = 0; i < 4; i++) System.out.println (pipeIn.read ());
输出
4280287229 vs -14680067
255
31
255
253
1048573 vs 1048573
0
15
255
253
符合预期
这篇关于Java读取unsigned int,存储并将其写回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!