本文整理汇总了Java中org.apache.jute.BinaryInputArchive.readBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java BinaryInputArchive.readBuffer方法的具体用法?Java BinaryInputArchive.readBuffer怎么用?Java BinaryInputArchive.readBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jute.BinaryInputArchive
的用法示例。
在下文中一共展示了BinaryInputArchive.readBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("USAGE: LogFormatter log_file");
System.exit(2);
}
FileInputStream fis = new FileInputStream(args[0]);
BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
FileHeader fhdr = new FileHeader();
fhdr.deserialize(logStream, "fileheader");
if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
System.err.println("Invalid magic number for " + args[0]);
System.exit(2);
}
System.out.println("ZooKeeper Transactional Log File with dbid "
+ fhdr.getDbid() + " txnlog format version "
+ fhdr.getVersion());
int count = 0;
while (true) {
long crcValue;
byte[] bytes;
try {
crcValue = logStream.readLong("crcvalue");
bytes = logStream.readBuffer("txnEntry");
} catch (EOFException e) {
System.out.println("EOF reached after " + count + " txns.");
return;
}
if (bytes.length == 0) {
// Since we preallocate, we define EOF to be an
// empty transaction
System.out.println("EOF reached after " + count + " txns.");
return;
}
Checksum crc = new Adler32();
crc.update(bytes, 0, bytes.length);
if (crcValue != crc.getValue()) {
throw new IOException("CRC doesn't match " + crcValue +
" vs " + crc.getValue());
}
TxnHeader hdr = new TxnHeader();
Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.LONG).format(new Date(hdr.getTime()))
+ " session 0x"
+ Long.toHexString(hdr.getClientId())
+ " cxid 0x"
+ Long.toHexString(hdr.getCxid())
+ " zxid 0x"
+ Long.toHexString(hdr.getZxid())
+ " " + TraceFormatter.op2String(hdr.getType()) + " " + txn);
if (logStream.readByte("EOR") != 'B') {
LOG.error("Last transaction was partial.");
throw new EOFException("Last transaction was partial.");
}
count++;
}
}
示例2: TxnLogSource
import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
public TxnLogSource(String file) throws IOException {
this.file = file;
skiplist = new LogSkipList();
RandomAccessFileReader reader = new RandomAccessFileReader(new File(file));
try {
BinaryInputArchive logStream = new BinaryInputArchive(reader);
FileHeader fhdr = new FileHeader();
fhdr.deserialize(logStream, "fileheader");
byte[] bytes = null;
while (true) {
long lastFp = reader.getPosition();
long crcValue;
try {
crcValue = logStream.readLong("crcvalue");
bytes = logStream.readBuffer("txnEntry");
} catch (EOFException e) {
break;
}
if (bytes.length == 0) {
break;
}
Checksum crc = new Adler32();
crc.update(bytes, 0, bytes.length);
if (crcValue != crc.getValue()) {
throw new IOException("CRC doesn't match " + crcValue +
" vs " + crc.getValue());
}
if (logStream.readByte("EOR") != 'B') {
throw new EOFException("Last transaction was partial.");
}
TxnHeader hdr = new TxnHeader();
Record r = SerializeUtils.deserializeTxn(bytes, hdr);
if (starttime == 0) {
starttime = hdr.getTime();
}
endtime = hdr.getTime();
if (size % skipN == 0) {
skiplist.addMark(hdr.getTime(), lastFp, size);
}
size++;
}
if (bytes == null) {
throw new IOException("Nothing read from ("+file+")");
}
} finally {
reader.close();
}
}