{"id":18291927,"url":"https://github.com/xxlabaza/log-file","last_synced_at":"2026-07-19T01:33:05.479Z","repository":{"id":57729839,"uuid":"225049730","full_name":"xxlabaza/log-file","owner":"xxlabaza","description":"A Java library for working with append-only files","archived":false,"fork":false,"pushed_at":"2020-01-31T18:26:54.000Z","size":70,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-09T17:05:06.829Z","etag":null,"topics":["write-ahead-log","write-to-file"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xxlabaza.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-30T17:54:30.000Z","updated_at":"2025-04-24T09:21:19.000Z","dependencies_parsed_at":"2022-09-11T07:00:24.962Z","dependency_job_id":null,"html_url":"https://github.com/xxlabaza/log-file","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xxlabaza/log-file","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2Flog-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2Flog-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2Flog-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2Flog-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xxlabaza","download_url":"https://codeload.github.com/xxlabaza/log-file/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2Flog-file/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35637763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-18T02:00:07.223Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["write-ahead-log","write-to-file"],"created_at":"2024-11-05T14:15:45.153Z","updated_at":"2026-07-19T01:33:05.442Z","avatar_url":"https://github.com/xxlabaza.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview log-file\n\n[![build_status](https://travis-ci.org/xxlabaza/log-file.svg?branch=master)](https://travis-ci.org/xxlabaza/log-file)\n[![maven_central](https://maven-badges.herokuapp.com/maven-central/com.xxlabaza.utils/log-file/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.xxlabaza.utils/log-file)\n[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)\n\nA Java library for working with append-only files (also known as the log files). The main methods of such files are:\n\n- **append** - for appending arbitary data;\n- **load** - for fully file read from the begining till the end.\n\n## Usage example\n\n```java\nimport java.nio.file.Paths;\n\nimport com.xxlabaza.utils.log.file.Config;\nimport com.xxlabaza.utils.log.file.LogFile;\n\nimport io.appulse.utils.Bytes;\nimport io.appulse.utils.HexUtil;\n\n\n// let's instantiate a log file:\nConfig config = Config.builder()\n    .path(Paths.get(\"./my.log\"))\n    .blockBufferSizeBytes(32)\n    .forceFlush(false)\n    .build();\n\nLogFile logFile = new LogFile(config);\n\n\n// than, write some data to log file\nBytes record = Bytes.resizableArray()\n    .write4B(42);\n\nlogFile.append(record);\n\n\n// now, read all records from the file and print them to STDOUT\nlogFile.load((buffer, position) -\u003e {\n  String dump = HexUtil.prettyHexDump(buffer);\n  System.out.println(dump);\n  return true; // true - continue reading, false - stop reading\n});\n\n\n// flush and close the file\nlogFile.close();\n```\n\n## Under the hood\n\nA log file has the next structure:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth align=\"center\" colspan=\"5\"\u003elog file structure\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" colspan=\"2\"\u003e\u003cb\u003efile header\u003c/b\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" colspan=\"3\"\u003e\u003cb\u003eblocks\u003c/b\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003eversion\u003c/td\u003e\n      \u003ctd align=\"center\"\u003eblock size\u003c/td\u003e\n      \u003ctd align=\"center\"\u003eblock 0\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e...\u003c/td\u003e\n      \u003ctd align=\"center\"\u003eblock n\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e1 byte\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e4 bytes\u003c/td\u003e\n      \u003ctd align=\"center\" colspan=\"3\"\u003eblocks count * \u003cb\u003eblock size\u003c/b\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n### File header\n\nFile header's description:\n\n\u003cdl\u003e\n  \u003cdt\u003eversion\u003c/dt\u003e\n  \u003cdd\u003eThe file's format version, which tells the features set is used in the file.\u003c/dd\u003e\n  \u003cdt\u003eblock size\u003c/dt\u003e\n  \u003cdd\u003eThe size of a block buffer, in bytes, which is used in the current file.\u003c/dd\u003e\n\u003c/dl\u003e\n\n### Block\n\nEach block consist of the records set:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth align=\"center\" colspan=\"3\"\u003eblock\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003erecord 1\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e...\u003c/td\u003e\n      \u003ctd align=\"center\"\u003erecord n\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nThe records have the following structure:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth align=\"center\" colspan=\"4\"\u003erecord\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003echecksum\u003c/td\u003e\n      \u003ctd align=\"center\"\u003etype\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ebody length\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ebody\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e4 bytes\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e1 byte\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e2 bytes\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ebody length\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003cdl\u003e\n  \u003cdt\u003echecksum\u003c/dt\u003e\n  \u003cdd\u003eThe checksum value, which is calculated from \u003cb\u003etype\u003c/b\u003e, \u003cb\u003ebody length\u003c/b\u003e and \u003cb\u003ebody\u003c/b\u003e values.\u003c/dd\u003e\n  \u003cdt\u003etype\u003c/dt\u003e\n  \u003cdd\u003eOne of the record's types:\n    \u003cul\u003e\n      \u003cli\u003e\u003cb\u003eFULL\u003c/b\u003e - the data is presented entirely in this record;\u003c/li\u003e\n      \u003cli\u003e\u003cb\u003eFIRST\u003c/b\u003e - it is the first chunk of data;\u003c/li\u003e\n      \u003cli\u003e\u003cb\u003eMIDDLE\u003c/b\u003e - one of the middle parts of data;\u003c/li\u003e\n      \u003cli\u003e\u003cb\u003eLAST\u003c/b\u003e - the last piece of data.\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/dd\u003e\n  \u003cdt\u003ebody length\u003c/dt\u003e\n  \u003cdd\u003eThe length of the next body section, in bytes.\u003c/dd\u003e\n  \u003cdt\u003ebody\u003c/dt\u003e\n  \u003cdd\u003ethe record's payload.\u003c/dd\u003e\n\u003c/dl\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxlabaza%2Flog-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxxlabaza%2Flog-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxlabaza%2Flog-file/lists"}