Package uk.ac.manchester.spinnaker.utils
Class ByteBufferUtils
java.lang.Object
uk.ac.manchester.spinnaker.utils.ByteBufferUtils
Utility methods for 
ByteBuffers.- 
Method SummaryModifier and TypeMethodDescriptionstatic ByteBufferlimitSlice(ByteBuffer src, int maxSize) Make a slice of a byte buffer if it exceeds a given size.static ByteBufferread(InputStream data, ByteBuffer workingBuffer, int maxRemaining) Read a chunk of an input stream into a byte buffer.static ByteBufferslice(ByteBuffer src, int from, int len) Make a slice of a byte buffer without modifying the original buffer.static MappableIterable<ByteBuffer>sliceUp(ByteBuffer src, int chunkSize) Slice up a buffer buffer into a sequence of (little-endian) byte buffers with a maximum size.
- 
Method Details- 
sliceMake a slice of a byte buffer without modifying the original buffer.- Parameters:
- src- The originating buffer.
- from- The offset into the originating buffer where the slice starts.
- len- The length of the slice.
- Returns:
- The little-endian slice. This will be read-only if and only if the original buffer is read-only.
 
- 
limitSliceMake a slice of a byte buffer if it exceeds a given size.- Parameters:
- src- The originating buffer.
- maxSize- The maximum size of the resulting buffer.
- Returns:
- The original buffer or a little-endian slice. This will be read-only if and only if the original buffer is read-only.
 
- 
sliceUpSlice up a buffer buffer into a sequence of (little-endian) byte buffers with a maximum size.- Parameters:
- src- The buffer to slice up.
- chunkSize- Max size of each chunk. Must be positive.
- Returns:
- An iterable of little-endian chunks. Only the final chunk will be smaller than the requested chunk size.
 
- 
readpublic static ByteBuffer read(InputStream data, ByteBuffer workingBuffer, int maxRemaining) throws IOException Read a chunk of an input stream into a byte buffer.- Parameters:
- data- Where to read from.
- workingBuffer- The buffer to use. The number of bytes remaining in the buffer is the maximum number of bytes to read unless the maximum bytes remaining is smaller.
- maxRemaining- The maximum number of bytes remaining in the input stream; bytes after that point won't be read even if they exist.
- Returns:
- A view on the buffer with the data in it (endianness undefined),
         or nullif EOF or the limit is reached.
- Throws:
- IOException- If reading fails.
 
 
-