- 0
- 0
- 约5.29千字
- 约 6页
- 2026-01-21 发布于北京
- 举报
1概述
当使用BookKeeperAPI时,应用程序必须将要写入的数据拆分为条目,每个条目
都是一个字节数组。这对于许多应用程序来说是自然的。例如,当使用
BookKeeper进行预写日志记录时,应用程序通常希望写入与命令或事务相对应的修
改。然而,其他一些应用程序可能没有条目的自然边界,并且可能更写入和
字节流。这正是我们在BookKeeper上实现的流API的目的。
流API实现在Streaming包中,并包含两个主要类:
LedgerOutputStream和LedgerInputStream。类名表明了它们的功能。
2写入字节流
类LedgerOutputStream实现了两个构造函数和五个公共方法:
publicLedgerOutputStream(LedgerHandlelh)
其中:
•lh是一个先前创建并打开的账本的句柄。
publicLedgerOutputStream(LedgerHandlelh,intsize)
其中:
•lh是先前创建并打开的分类帐的句柄。
•size是用于写入字节的字节缓冲区的大小,在刷新之前。
关闭流。此调用通过刷新写入缓冲区来关闭流。
publicvoidclose()
该方法没有参数。
刷新流。此调用实际上会刷新写入缓冲区。
publicsynchronizedvoidflush()
没有参数。
写入字节。有三种调用可以将字节写入流中。
publicsynchronizedvoidwrite(byte[]b)
其中:
•b是要写入的字节数组。
publicsynchronizedvoidwrite(byte[]b,intoff,intlen)其中:
1Summary
WhenusingtheBookKeeperAPI,anapplicationhastosplitthedatatowriteintoentries,
eachentrybeingabytearray.Thisisnaturalformanyapplications.Forexample,when
usingBookKeeperforwrite-aheadlogging,anapplicationtypicallywantstowritethe
modificationscorrespondingtoacommandoratransaction.Someotherapplications,
however,mightnothaveanaturalboundaryforentries,andmayprefertowriteandread
streamsofbytes.ThisisexactlythepurposeofthestreamAPIwehaveimplementedontop
ofBookKeeper.
ThestreamAPIisimplementedinthepackageStreaming,anditcontainstwomain
classes:LedgerOutputStreamandLedgerInputStream.Theclassnamesare
indicativeofwhattheydo.
2Writingastreamofbytes
ClassLedgerOutputStreamimplementstwoconstructorsandfivepublicmethods:
publicLedgerOutputStream(LedgerHandlelh)
where:
•lhisaledgerhandleforapreviouslycreatedandopenledger.
publicLedgerOutputStream(LedgerHandlelh,intsize)
where:
•lhisaledgerhandlefor
您可能关注的文档
最近下载
- 2025-2026学年浙教版科学七年级上册科学期末专项训练 综合题汇编(含答案).pdf VIP
- 期末复习+课件-2025-2026学年浙教版科学七年级上册科学.pptx VIP
- 市医疗保障局党组副书记2024年民主生活会个人对照检查发言材料.docx VIP
- 无偿划转债务处置方案.docx VIP
- 湖南省长沙市第一中学2025-2026学年高三上学期1月月考物理试题.pdf VIP
- 苗木采购整体供货方案.docx VIP
- 东风风神-E70-产品使用说明书-东风风神E70 2019款 专享版-DFM7000G1F6BEV-E70使用说明书201903.pdf VIP
- 奥的斯电梯JARLESS-CON中分门机中文版.pdf VIP
- 食堂居间合同协议.docx VIP
- 初中数学圆的训练.pdf VIP
原创力文档

文档评论(0)