MCPcopy Create free account
hub / github.com/amazon-ion/ion-java / BlockedBuffer

Class BlockedBuffer

src/main/java/com/amazon/ion/impl/BlockedBuffer.java:38–1778  ·  view source on GitHub ↗

This implements a blocked byte buffer and both an input and output stream that operates over it. It is designed to be able to be randomly accessed. The output steam supports both inserting data (with "stretching") in the middle of the stream and over-write. The output steam also supports remove whi

Source from the content-addressed store, hash-verified

36 * GC, if that is desirable.
37 */
38final class BlockedBuffer
39{
40 ///////////////////////////////////////////////////////////////////////////////
41 //
42 // updatable, insertable, and possibly fragmented byte buffer
43 //
44 // these manage the set of memory (byte) buffers
45 ArrayList<bbBlock> _blocks;
46 int _next_block_position; // next position in _blocks for active block, may be less than _blocks.size()
47 int _lastCapacity; // used to allocate new blocks
48 int _buf_limit; // high water mark of _position
49 int _version;
50 int _mutation_version;
51 Object _mutator;
52// BUGBUG - this is just a test, it shouldn't be in checked in code
53static final boolean test_with_no_version_checking = false;
54 void start_mutate(Object caller, int version) {
55 if (test_with_no_version_checking) return;
56 if (_mutation_version != 0 || _mutator != null)
57 throw new BlockedBufferException("lock conflict");
58 if (version != _version)
59 throw new BlockedBufferException("version conflict on update");
60 _mutator = caller;
61 _mutation_version = version;
62 }
63 int end_mutate(Object caller) {
64 if (test_with_no_version_checking) return _version;
65 if (_version != _mutation_version)
66 throw new BlockedBufferException("version mismatch failure");
67 if (caller != _mutator)
68 throw new BlockedBufferException("caller mismatch failure");
69 _version = _mutation_version + 1;
70 _mutation_version = 0;
71 _mutator = null;
72 return _version;
73 }
74 boolean mutation_in_progress(Object caller, int version) {
75 if (test_with_no_version_checking) return false;
76 if (_mutation_version != version)
77 throw new BlockedBufferException("unexpected update lock conflict");
78 if (caller != _mutator)
79 throw new BlockedBufferException("caller mismatch failure");
80 return true;
81 }
82 int getVersion() {
83 return _version;
84 }
85 static boolean debugValidation = false;
86 static int _defaultBlockSizeMin;
87 static int _defaultBlockSizeUpperLimit;
88 static {
89 resetParameters();
90 }
91 public static void resetParameters() {
92 debugValidation = false;
93 _defaultBlockSizeMin = 4096 * 8;
94 _defaultBlockSizeUpperLimit = 4096 * 8;
95 }

Callers

nothing calls this directly

Calls 2

resetParametersMethod · 0.95
getComparatorMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…