2

我需要从 quicktime 文件中读取 unsigned int,然后将其写回另一个 quicktime 文件。

目前,我将 unsigned int 读入 Long 但在写回它时,我从未设法将确切的数字以 4 个字节写回 unsigned int。long 具有我需要写回的正确值。(例如 3289763894 或 370500)我什至无法读取小于 Integer.MAX_VALUE 的数字(例如 2997)。

我正在使用以下方法将值写回

 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);
    }

任何帮助,将不胜感激。

4

2 回答 2

4

只需将您的长期转换为 int 即可。我检查了:


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 与 -14680067
255
31
255
253
1048573 与 1048573
0
15
255
253
正如预期的那样

于 2011-09-22T09:23:15.540 回答
0

如果你只想读取、存储和重写它,那么你可以使用 int。更一般地说:只要您不解释这些位,您就可以读取、存储和写入它们,而无需关心这些位的预期解释

于 2011-09-22T09:51:45.443 回答