Skip to content

Commit 69da8f3

Browse files
committed
Add utility methods to StreamUtil
1 parent 5b13608 commit 69da8f3

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

pg/src/main/java/org/bouncycastle/bcpg/StreamUtil.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,33 @@ static void writeTime(BCPGOutputStream pOut, long time)
115115
pOut.write((byte)time);
116116
}
117117

118+
static long readTime(BCPGInputStream in)
119+
throws IOException {
120+
return (((long)in.read() << 24) | ((long) in.read() << 16) | ((long) in.read() << 8) | in.read()) * 1000;
121+
}
122+
123+
static void write2OctetLength(OutputStream pOut, int len)
124+
throws IOException {
125+
pOut.write(len >> 8);
126+
pOut.write(len);
127+
}
128+
129+
static int read2OctetLength(InputStream in)
130+
throws IOException {
131+
return (in.read() << 8) | in.read();
132+
}
133+
134+
static void write4OctetLength(OutputStream pOut, int len)
135+
throws IOException {
136+
pOut.write(len >> 24);
137+
pOut.write(len >> 16);
138+
pOut.write(len >> 8);
139+
pOut.write(len);
140+
}
141+
142+
static int read4OctetLength(InputStream in)
143+
throws IOException {
144+
return (in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read();
145+
}
118146

119147
}

0 commit comments

Comments
 (0)