Maps the segment writer into memory, returning the mapped buffer.

@return the buffer that was mapped into memory
433977
MappedByteBuffer map() {
    if (writer instanceof MappedJournalSegmentWriter) {
      return ((MappedJournalSegmentWriter<E>) writer).buffer();
    }

    try {
      JournalWriter<E> writer = this.writer;
      MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, segment.descriptor().maxSegmentSize());
      this.writer = new MappedJournalSegmentWriter<>(buffer, segment, maxEntrySize, index, namespace);
      writer.close();
      return buffer;
    } catch (IOException e) {
      throw new StorageException(e);
    }
  }
785091
JournalSegmentDescriptor copyTo(ByteBuffer buffer) {
    buffer.putInt(version);
    buffer.putLong(id);
    buffer.putLong(index);
    buffer.putInt(maxSegmentSize);
    buffer.putInt(maxEntries);
    buffer.putLong(updated);
    buffer.put(locked ? (byte) 1 : (byte) 0);
    return this;
  }
237041
public static byte[] copyToBytes(MemorySegment[] segments, int offset, int numBytes) {
		return copyToBytes(segments, offset, new byte[numBytes], 0, numBytes);
	}
863303
public static Buffer toBuffer(AbstractEvent event) throws IOException {
		final ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event);

		MemorySegment data = MemorySegmentFactory.wrap(serializedEvent.array());

		final Buffer buffer = new NetworkBuffer(data, FreeingBufferRecycler.INSTANCE, false);
		buffer.setSize(serializedEvent.remaining());

		return buffer;
	}
147418
public ByteBuffer preProcessOneWriteBuffer() {
        // We can process the single buffer case more efficiently than if we
        // include it as a part of the multi-buffer logic
        WsByteBufferImpl wsBuffImpl = null;
        try {
            wsBuffImpl = (WsByteBufferImpl) getBuffer();
        } catch (ClassCastException cce) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Writing with a non-WsByteBufferImpl");
            }
            return getBuffer().getWrappedByteBuffer();
        }

        if (!wsBuffImpl.isDirect() && wsBuffImpl.hasArray()) {
            wsBuffImpl.copyToDirectBuffer();
            return wsBuffImpl.oWsBBDirect;
        }
        return wsBuffImpl.getWrappedByteBufferNonSafe();
    }
1173243
public ByteBuffer getIndicesBuffer() {
        final ByteBuffer buffer = CausticUtil.createByteBuffer(indices.size() * DataType.INT.getByteSize());
        for (int i = 0; i < indices.size(); i++) {
            buffer.putInt(indices.get(i));
        }
        buffer.flip();
        return buffer;
    }
1058007
private int writeBuffer(java.nio.ByteBuffer byteBuffer,
                            long byteAddress)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "writeBuffer",
                        new Object[] { new Integer(byteBuffer.hashCode()), new Long(byteAddress) }
                            );

        // Write the bytes.
        int bytesWritten = 0;
        try {
            while (byteBuffer.hasRemaining()) {
                bytesWritten = bytesWritten + storeChannel.write(byteBuffer,
                                                                 byteAddress + bytesWritten);
            } // while (byteBuffer.hasRemaining()).
        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, "writeBuffer", exception, "1:833:1.39");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           "writeBuffer");

            // cannot continue
            objectManagerState.requestShutdown();
            throw new PermanentIOException(this,
                                           exception);
        } // catch.

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "writeBuffer",
                       new Object[] { new Integer(bytesWritten) });
        return bytesWritten;
    }
1164565
function() {
    if (this.buffers.length) {
      var last = this.buffers[this.buffers.length - 1];
      if (!last.full) {
        return last;
      }
    }
    var buf = new ReadWriteBuf(this.bufSize);
    this.buffers.push(buf);
    return buf;
  }
1149339
private int fillBuffer() throws IOException {
    int cnt = 0;
    int rem = this.buff_.length;
    while (rem > 0) {
      int n = super.read(this.buff_, cnt, rem);
      if (n < 0) {
        break;
      }
      cnt += n;
      rem -= n;
    }
    if ((cnt < 0) && (this.hitEOF_ = (cnt < this.buff_.length))) {
      // make sure buffer that wasn't read is initialized with -1
      Arrays.fill(this.buff_, cnt, this.buff_.length, (byte) 0xff);
    }
    this.diskPos_ += cnt;
    return cnt;
  }
1134969
@Override
	public int writeTo(BitWriter writer) {
		if (writer == null) throw new IllegalArgumentException("null writer");
		return writer.write(bits, 64);
	}
1091912
public ByteBuffer serialize () {

        final int size = uncroppedSize();
        if (size == 0) return ByteBuffer.allocate(0);// empty data segment

        // calculate sense length
        int senseLength;
        if (senseData == null)
            senseLength = 0;
        else
            senseLength = senseData.size();

        // allocate buffer of appropriate size
        final ByteBuffer buffer = ByteBuffer.allocate(size);

        // write sense length field
        ReadWrite.writeTwoByteInt(buffer,// buffer
                senseLength,// value
                0);// index

        // write sense data
        if (senseData != null) senseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH);

        // write and SCSI response data
        if (responseData != null) responseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH + senseLength);

        if (allocationLength > 0 && buffer.capacity() > allocationLength) {
            /*
             * If the allocation length variable is valid and the response data segment is larger than the data-in
             * buffer allocated by the initiator, limit the number of bytes returned.
             */
            buffer.position(0);
            buffer.limit(allocationLength);
            final ByteBuffer croppedBuffer = ByteBuffer.allocate(allocationLength);
            croppedBuffer.put(buffer);
            return croppedBuffer;
        }

        if (LOGGER.isDebugEnabled()) LOGGER.debug("SCSI Response Data Segment:\n" + Debug.byteBufferToString(buffer));

        return buffer;
    }
681158
public static BinaryInMemorySortBuffer createBuffer(
			NormalizedKeyComputer normalizedKeyComputer,
			AbstractRowSerializer<BaseRow> inputSerializer,
			BinaryRowSerializer serializer,
			RecordComparator comparator,
			List<MemorySegment> memory) throws IOException {
		checkArgument(memory.size() >= MIN_REQUIRED_BUFFERS);
		int totalNumBuffers = memory.size();
		ListMemorySegmentPool pool = new ListMemorySegmentPool(memory);
		ArrayList<MemorySegment> recordBufferSegments = new ArrayList<>(16);
		return new BinaryInMemorySortBuffer(
				normalizedKeyComputer, inputSerializer, serializer, comparator, recordBufferSegments,
				new SimpleCollectingOutputView(recordBufferSegments, pool, pool.pageSize()),
				pool, totalNumBuffers);
	}
1267507
public ShortBuffer toShortBuffer() {
    ShortBuffer sb = ShortBuffer.allocate(this.cardinality);
    sb.put(this.content, 0, this.cardinality);
    return sb;
  }
1027643
public int writeTo(ByteBuffer bb) throws IOException
    {
        return writeTo((srcs, offset, len)->ByteBuffers.move(srcs, offset, len, bb), writeToSplitter);
    }
329737
public ByteBuffer toByteBuffer() {
    // Allow room for encoded message, plus the type byte
    ByteBuf buf = Unpooled.buffer(encodedLength() + 1);
    buf.writeByte(type().id);
    encode(buf);
    assert buf.writableBytes() == 0 : "Writable bytes remain: " + buf.writableBytes();
    return buf.nioBuffer();
  }
918222
public int write( final ByteBuffer buffer) throws IOException {
		for ( Consumer< ?> consumer : consumers.values()) consumer.consume( buffer.duplicate());
		return channel.write( buffer);
	}

	/**
	 * Closes the underlying channel and completes
	 * any outstanding operations in the consumers.
	 *
	 * @throws IOException if an IO error occurs
	 */
	public void close() throws IOException {
		channel.close();
		super.close();
	}

	/**
	 * Flag indicating whether the underlying channel
	 * is open.
	 *
	 * @return true if it is open, false otherwise
	 */
	public boolean isOpen() {
		return channel.isOpen();
	}
}
303464
public static char getChar(MemorySegment[] segments, int offset) {
		if (inFirstSegment(segments, offset, 2)) {
			return segments[0].getChar(offset);
		} else {
			return getCharMultiSegments(segments, offset);
		}
	}