void (Key key, @NotNull BufferExposingByteArrayOutputStream bytes) { myEnumerator.lockStorageWrite(); try { long previousRecord; final int id; if (myDirectlyStoreLongFileOffsetMode) { previousRecord = ((PersistentBTreeEnumerator<Key>)myEnumerator).getNonNegativeValue(key); id = -1; } else { id = enumerate(key); previousRecord = readValueId(id); } long headerRecord = myValueStorage.appendBytes(bytes.toByteArraySequence(), previousRecord); if (myDirectlyStoreLongFileOffsetMode) { ((PersistentBTreeEnumerator<Key>)myEnumerator).putNonNegativeValue(key, headerRecord); } else { updateValueId(id, headerRecord, previousRecord, key, 0); } if (previousRecord == NULL_ADDR) { myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; } if (bytes.getInternalBuffer().length <= MAX_RECYCLED_BUFFER_SIZE) { // Avoid internal fragmentation by not retaining / reusing large append buffers (IDEA-208533) myStreamPool.recycle(bytes); } } catch (ClosedStorageException ex) { //TODO rethrow original throw new RuntimeException(ex); } catch (IOException e) { markCorrupted(); //TODO rethrow original throw new RuntimeException(e); } finally { myEnumerator.unlockStorageWrite(); } }