Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(See See <a href="http://java.sun.com/javase/6/docs/api/java/nio/ByteBuffer.html#slice%28%29" rel="nofollow noreferrer">http://java.sun.com/javase/6/docs/api/java/nio/ByteBuffer.html#slice%28%29</a> and <a href="http://java.sun.com/javase/6/docs/api/java/nio/Buffer.html#flip%28%29" rel="nofollow noreferrer">http://java.sun.com/javase/6/docs/api/java/nio/Buffer.html#flip%28%29</a> for java's calls)</p> <p>Flip is a quick way to reset the buffer. So for example (pseudocode)</p> <pre><code>void flip() { Length = currentPos; currentPos = 0; } </code></pre> <p>Allows you to quickly setup the buffer you presumably just wrote to for reading from the beginning.</p> <p><strong>Update:</strong> Splice is a bit trickier due to the requirement that "Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent". There unfortunately is no concept of a shared portion of buffer (that i know of - theres always using arrays, detailed below) without making your own class. The closest thing you could do is this:</p> <p>Old Code: </p> <pre><code>ByteBuffer b = buff.slice(); </code></pre> <p>New Code (assuming a List)</p> <pre><code>List&lt;Byte&gt; b= buff; int bStart = buffPos; // buffPos is your way of tracking your mark </code></pre> <p>the downside to the code above is that there is no way for c# to hold the new starting point of the new buffer and still share it. You'll have to manually use the new starting point whenever you do anything, from for loops (for i=bStart;...) to indexing (newList[i + bStart]...)</p> <p>Your other option is to do use Byte[] arrays instead, and do something like this:</p> <pre><code>Byte[] b = &amp;buff[buffPos]; </code></pre> <p>... however that requires unsafe operations to be enabled, and I cannot vouch for its saftey, due to the garbage collector and my avoidance of the "unsafe" features.</p> <p>Outside of that, theres always making your own ByteBuffer class.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload