{"id":3654,"url":"https://github.com/square/tape","last_synced_at":"2025-11-21T13:30:16.618Z","repository":{"id":4602504,"uuid":"5745625","full_name":"square/tape","owner":"square","description":"A lightning fast, transactional, file-based FIFO for Android and Java.","archived":true,"fork":false,"pushed_at":"2023-03-18T23:20:25.000Z","size":874,"stargazers_count":2467,"open_issues_count":27,"forks_count":287,"subscribers_count":120,"default_branch":"master","last_synced_at":"2024-10-29T15:05:10.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://square.github.io/tape/","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/square.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-09-10T06:18:49.000Z","updated_at":"2024-10-25T21:33:17.000Z","dependencies_parsed_at":"2023-07-05T17:15:25.777Z","dependency_job_id":null,"html_url":"https://github.com/square/tape","commit_stats":{"total_commits":193,"total_committers":27,"mean_commits":7.148148148148148,"dds":0.6010362694300518,"last_synced_commit":"445cd3fd0a7b3ec48c9ea3e0e86663fe6d3735d8"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Ftape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Ftape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Ftape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Ftape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/square","download_url":"https://codeload.github.com/square/tape/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239625997,"owners_count":19670790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-01-05T20:16:47.624Z","updated_at":"2025-11-21T13:30:16.570Z","avatar_url":"https://github.com/square.png","language":"Java","readme":"Tape by Square, Inc.\n====================\n\nTape is a collection of queue-related classes for Android and Java.\n\n`QueueFile` is a lightning-fast, transactional, file-based FIFO. Addition and\nremoval from an instance is an O(1) operation and is atomic. Writes are\nsynchronous; data will be written to disk before an operation returns. The\nunderlying file is structured to survive process and even system crashes and if\nan I/O exception is thrown during a mutating change, the change is aborted.\n\n**NOTE:** The current implementation is built for file systems that support\natomic segment writes (like YAFFS). Most conventional file systems don't support\nthis; if the power goes out while writing a segment, the segment will contain\ngarbage and the file will be corrupt.\n\nAn `ObjectQueue` represents an ordering of arbitrary objects which can be backed\neither by the filesystem (via `QueueFile`) or in memory only.\n\n\n\nDownload\n--------\n\nDownload [the latest JAR][2] or grab via Maven:\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.squareup.tape2\u003c/groupId\u003e\n  \u003cartifactId\u003etape\u003c/artifactId\u003e\n  \u003cversion\u003e2.0.0-beta1\u003c/version\u003e\n\u003c/dependency\u003e\n```\nor Gradle:\n```groovy\ncompile 'com.squareup.tape2:tape:2.0.0-beta1'\n```\n\nSnapshots of the development version are available in [Sonatype's `snapshots` repository][snap].\n\n\n\nUsage\n-----\n\nCreate a `QueueFile` instance.\n\n```java\nFile file = // ...\nQueueFile queueFile = new QueueFile.Builder(file).build();\n```\n\nAdd some data to the queue to the end of the queue. `QueueFile` accepts a `byte[]` of arbitrary length.\n\n```java\nqueueFile.add(\"data\".getBytes());\n```\n\nRead data at the head of the queue.\n\n```java\nbyte[] data = queueFile.peek();\n```\n\nRemove processed elements.\n\n```java\n// Remove the eldest element.\nqueueFile.remove();\n\n// Remove multiple elements.\nqueueFile.remove(n);\n\n// Remove all elements.\nqueueFile.clear();\n```\n\nRead and process multiple elements with the iterator API.\n\n```java\nIterator\u003cbyte[]\u003e iterator = queueFile.iterator();\nwhile (iterator.hasNext()) {\n  byte[] element = iterator.next();\n  process(element);\n  iterator.remove();\n}\n```\n\nWhile `QueueFile` works with `byte[]`, `ObjectQueue` works with arbitrary Java objects with a similar API. An `ObjectQueue` may be backed by a persistent `QueueFile`, or in memory. A persistent `ObjectQueue` requires a [`Converter`](#converter) to encode and decode objects.\n\n```java\n// A persistent ObjectQueue.\nObjectQueue\u003cString\u003e queue = ObjectQueue.create(queueFile, converter);\n\n// An in-memory ObjectQueue.\nObjectQueue\u003cString\u003e queue = ObjectQueue.createInMemory();\n```\n\nAdd some data to the queue to the end of the queue.\n\n```java\nqueue.add(\"data\");\n```\n\nRead data at the head of the queue.\n\n```java\n// Peek the eldest elements.\nString data = queue.peek();\n\n// Peek the eldest `n` elements.\nList\u003cString\u003e data = queue.peek(n);\n\n// Peek all elements.\nList\u003cString\u003e data = queue.asList();\n```\n\nRemove processed elements.\n\n```java\n// Remove the eldest element.\nqueue.remove();\n\n// Remove multiple elements.\nqueue.remove(n);\n\n// Remove all elements.\nqueue.clear();\n```\n\nRead and process multiple elements with the iterator API.\n\n```java\nIterator\u003cString\u003e iterator = queue.iterator();\nwhile (iterator.hasNext()) {\n  String element = iterator.next();\n  process(element);\n  iterator.remove();\n}\n```\n\n\n\nConverter\n---------\n\nA `Converter` encodes objects to bytes and decodes objects from bytes.\n\n```java\n/** Converter which uses Moshi to serialize instances of class T to disk. */\nclass MoshiConverter\u003cT\u003e implements Converter\u003cT\u003e {\n  private final JsonAdapter\u003cT\u003e jsonAdapter;\n\n  public MoshiConverter(Moshi moshi, Class\u003cT\u003e type) {\n    this.jsonAdapter = moshi.adapter(type);\n  }\n\n  @Override public T from(byte[] bytes) throws IOException {\n    return jsonAdapter.fromJson(new Buffer().write(bytes));\n  }\n\n  @Override public void toStream(T val, OutputStream os) throws IOException {\n    try (BufferedSink sink = Okio.buffer(Okio.sink(os))) {\n      jsonAdapter.toJson(sink, val);\n    }\n  }\n}\n```\n\n\nLicense\n-------\n\n    Copyright 2012 Square, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n\n\n [1]: http://square.github.com/tape/\n [2]: https://search.maven.org/remote_content?g=com.squareup\u0026a=tape\u0026v=LATEST\n [snap]: https://oss.sonatype.org/content/repositories/snapshots/\n","funding_links":[],"categories":["I. Development","Background Processing","Libraries","Projects","Java","Data Structures","项目","Libs","库"],"sub_categories":["6. Useful libraries","Other","Data Structures","数据结构","\u003cA NAME=\"Utility\"\u003e\u003c/A\u003eUtility","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#other)其他"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Ftape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquare%2Ftape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Ftape/lists"}