{"id":48093,"date":"2017-06-29T11:00:29","date_gmt":"2017-06-29T08:00:29","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=48093"},"modified":"2019-03-12T11:27:49","modified_gmt":"2019-03-12T09:27:49","slug":"java-nio-heapbytebuffer-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/","title":{"rendered":"Java Nio HeapByteBuffer Example"},"content":{"rendered":"<p>This example demonstrates the usage of the Java Nio <code>HeapByteBuffer<\/code>. The Java Nio <code>HeapByteBuffer<\/code> is an odd class, one you will never reference directly and for good reason, it&#8217;s package private. Although it&#8217;s use is almost guaranteed when working with <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffers<\/a> unless you opt for a <code>DirectByteBuffer<\/code> (off heap). By virtue of extending <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffer<\/a>, it&nbsp;also happens to extend&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/Buffer.html\">Buffer<\/a>&nbsp;and implement&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/lang\/Comparable.html\">Comparable<\/a>.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;\n<\/p>\n<h2>1. Introduction<\/h2>\n<p>A Java Nio <code>HeapByteBuffer<\/code> is created via calling the following methods on the <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffer<\/a> class:<\/p>\n<ul>\n<li><code>allocate(int)<\/code><\/li>\n<li><code>wrap(byte[], int, int)<\/code><\/li>\n<li><code>wrap(byte[])<\/code><\/li>\n<\/ul>\n<p>All of the <code>get(...)<\/code>and <code>put(...)<\/code>methods defined on the super abstract class <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffer<\/a> return the current implementation owing to the fluent API design. If the actual implementation have been a <code>HeapByteBuffer<\/code> then this will surely be returned.<\/p>\n<p><code>HeapByteBuffer<\/code> further specializes into <code>HeapByteBufferR<\/code> which is a read only implementation for a <code>HeapByteBuffer<\/code> disallowing mutations and ensuring that &#8220;views&#8221; of this type of <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffer<\/a> only return an instance of <code>HeapByteBufferR<\/code> and not the superclass, thus protecting the invariant. A <code>HeapByteBufferR<\/code>&nbsp;instance is created by calling <code>asReadOnlyBuffer()<\/code>on an instance of <code>HeapByteBuffer<\/code>.<\/p>\n<h2>2. Technologies used<\/h2>\n<p>The example code in this article was built and run using:<\/p>\n<ul>\n<li>Java 1.8.101 (1.8.x will do fine)<\/li>\n<li>Maven 3.3.9 (3.3.x will do fine)<\/li>\n<li>Spring source tool suite 4.6.3 (Any Java IDE would work)<\/li>\n<li>Ubuntu 16.04 (Windows, Mac or Linux will do fine)<\/li>\n<\/ul>\n<h2>3. Overview<\/h2>\n<p>This article builds upon a previous <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/nio\/java-nio-bytebuffer-example\/\">article<\/a> on <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffers<\/a> in general and I would recommend to read that article first before continuing with this one. <code>HeapByteBuffers<\/code> are simply the default implementation provided when creating a <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffer<\/a> via the 3 methods listed in the introduction.<\/p>\n<p>One way to ensure you are working with a a <code>HeapByteBuffer<\/code> implementation is to call the <code>isDirect()<\/code>method which will return <code>false<\/code>&nbsp;for <code>HeapByteBuffer<\/code> and <code>HeapByteBufferR<\/code> implementations.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><code>HeapByteBuffer<\/code> instances are, barring escape analysis, always allocated on the Java heap and thus are wonderfully managed by the GC. <code>DirectByteBuffers<\/code> are not and thus are not easily quantifiable in terms of space.<\/p>\n<p>The reasons for the differentiation stem from the fact that the Operating system can optimize IO operations on <code>DirectByteBuffers<\/code>&nbsp;because the bytes are guaranteed to be physically contiguous, whereas heap memory is at the whim of the GC and thus means that <code>HeapByteBuffer<\/code> bytes may not necessarily be contiguous.<\/p>\n<h2>4. Test cases<\/h2>\n<p><span style=\"text-decoration: underline\"><em>Testing a HeapByteBuffer identity<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[24,25,26]; wrap-lines: false\">public class HeapByteBufferIdentityTest {\n\n    @Test\n    public void isHeapBuffer() {\n        final ByteBuffer heapBuffer = ByteBuffer.allocate(5 * 10000);\n        final ByteBuffer directBuffer = ByteBuffer.allocateDirect(5 * 10000);\n\n        assertTrue(\"Must be direct\", directBuffer.isDirect());\n        assertTrue(\"Must not be direct\", !heapBuffer.isDirect());\n    }\n\n    @Test\n    public void persistenIdentityChecker() {\n        final ByteBuffer buffer = ByteBuffer.allocate(5 * 10000);\n\n        check(buffer, (a) -&gt; !a.duplicate().isDirect());\n        check(buffer, (a) -&gt; !a.slice().isDirect());\n        check(buffer, (a) -&gt; !a.put(\"I am going to trick this buffer\".getBytes()).isDirect());\n        check(buffer, (a) -&gt; !a.asIntBuffer().isDirect());\n        check(buffer, (a) -&gt; !a.asCharBuffer().isDirect());\n        check(buffer, (a) -&gt; !a.asFloatBuffer().isDirect());\n    }\n\n    private void check(final ByteBuffer buffer, final Predicate&lt;? super ByteBuffer&gt; action) {\n        assertTrue(action.test(buffer));\n    }\n}\n<\/pre>\n<ul>\n<li>line 24-26: we accept a predicate which asserts the fact that the <code>HeapByteBuffer<\/code> stays a <code>HeapByteBuffer<\/code> regardless of the operation we performed on it.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>Testing a HeapByteBuffer memory vs DirectByteBuffer<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[24,25,26]; wrap-lines: false\">public class HeapByteBufferMemoryTest {\n\n    private static final Runtime RUNTIME = Runtime.getRuntime();\n\n    private ByteBuffer heapBuffer;\n    private ByteBuffer directBuffer;\n    private long startFreeMemory;\n\n    @Before\n    public void setUp() {\n        this.startFreeMemory = RUNTIME.freeMemory();\n    }\n\n    @Test\n    public void memoryUsage() {\n        this.heapBuffer = ByteBuffer.allocate(5 * 100000);\n        long afterHeapAllocation = RUNTIME.freeMemory();\n        assertTrue(\"Heap memory did not increase\", afterHeapAllocation &gt; this.startFreeMemory);\n\n        this.directBuffer = ByteBuffer.allocateDirect(5 * 100000);\n        assertTrue(\"Heap memory must not increase\", RUNTIME.freeMemory() &gt;= afterHeapAllocation);\n    }\n}\n<\/pre>\n<ul>\n<li>In this test case we attempt to prove that allocating a <code>HeapByteBuffer<\/code> will have an impact on heap memory usage whereas the allocation of a <code>DirectByteBuffer<\/code> will not.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>Testing the read only properties of a HeapByteBuffer<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[35,36,37,38,39,40,41]; wrap-lines: false\">public class HeapByteBufferReadOnlyTest {\n    private ByteBuffer buffer;\n\n    @Before\n    public void setUp() {\n        this.buffer = ByteBuffer.allocate(5 * 10000);\n    }\n\n    @Test(expected = ReadOnlyBufferException.class)\n    public void readOnly() {\n        this.buffer = this.buffer.asReadOnlyBuffer();\n        assertTrue(\"Must be readOnly\", this.buffer.isReadOnly());\n        this.buffer.putChar('b');\n    }\n\n    @Test(expected = ReadOnlyBufferException.class)\n    public void readOnlyWithManners() {\n        this.buffer = this.buffer.asReadOnlyBuffer();\n        assertTrue(\"Must be readOnly\", this.buffer.isReadOnly());\n        this.buffer.put(\"Please put this in the buffer\".getBytes());\n    }\n\n    @Test\n    public void persistenReadOnlyChecker() {\n        this.buffer = buffer.asReadOnlyBuffer();\n\n        check(this.buffer, (a) -&gt; a.duplicate().put(\"I am going to trick this buffer\".getBytes()));\n        check(this.buffer, (a) -&gt; a.slice().put(\"I am going to trick this buffer\".getBytes()));\n        check(this.buffer, (a) -&gt; a.put(\"I am going to trick this buffer\".getBytes()));\n        check(this.buffer, (a) -&gt; a.asIntBuffer().put(1));\n        check(this.buffer, (a) -&gt; a.asCharBuffer().put('c'));\n        check(this.buffer, (a) -&gt; a.asFloatBuffer().put(1f));\n    }\n\n    private void check(final ByteBuffer buffer, final Consumer&gt;? super ByteBuffer&lt; action) {\n        try {\n            action.accept(buffer);\n            fail(\"Must throw exception\");\n        } catch (ReadOnlyBufferException e) {\n        }\n    }\n}\n<\/pre>\n<ul>\n<li>lines 35-41: we invoke a function that should throw a <code>ReadOnlyBufferException<\/code> proving the property of read only despite creating a different view of the <code>HeapByteBuffer<\/code> through it&#8217;s api. Various methods are called ranging from <code>put(...)<\/code>to <code>duplicate()<\/code>, <code>sice()<\/code>&nbsp;etc. to try and break this property<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>Cloning a HeapByteBuffer into a DirectByteBuffer<\/em><\/span>[ulp id=&#8217;lQeyBcYaL5DqTMXI&#8217;]<\/p>\n<pre class=\"brush:java; highlight:[18,19,20,21,22]; wrap-lines: false\">public class HeapByteBufferIdentityCrisisTest {\n\n    @Test\n    public void shapeShift() {\n        final ByteBuffer buffer = ByteBuffer.wrap(\"Hello world!\".getBytes());\n        assertTrue(\"Not a heap buffer\", !buffer.isDirect());\n        \n        final ByteBuffer shapeShifter = ByteBuffer.allocateDirect(buffer.capacity()).put(getBytes(buffer));\n        assertTrue(\"Not a direct buffer\", shapeShifter.isDirect());\n        \n        shapeShifter.flip();\n        byte [] contents = new byte[shapeShifter.capacity()];\n        shapeShifter.get(contents);\n        \n        assertEquals(\"Invalid text\", \"Hello world!\", new String(contents).trim());\n    }\n    \n    private byte [] getBytes(final ByteBuffer buffer) {\n        byte [] dest = new byte[buffer.remaining()];\n        buffer.get(dest);\n        return dest;\n    }\n}\n<\/pre>\n<ul>\n<li>lines 18-22 we copy the bytes (remaining) between <code>position<\/code>and <code>limit<\/code>into a destination <code>byte []<\/code>. This is to ensure that the content of the original <code>HeapByteBuffer<\/code> are exumed and made ready for insertion into a coming <code>DirectByteBuffer<\/code><\/li>\n<li>I did not concern myself with encoding and decoding explicitness in this test. I refer you to a previous <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/nio\/java-nio-bytebuffer-example\/\">article<\/a> in this series which does those test cases explicit in the <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/charset\/Charset.html\">Charset<\/a> usage during encoding and decoding.<\/li>\n<\/ul>\n<h2>5. Summary<\/h2>\n<p>This example demonstrated the creation and usage of a <code>HeapByteBuffer<\/code> implementation of a <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\">ByteBuffer<\/a>. It proved properties of the API and attempted to demonstrate the core difference in implementation between this and a <code>DirectByteBuffer<\/code> in terms of memory allocation.<\/p>\n<h2>6. Download the source code<\/h2>\n<p>This was a Java Nio HeapByteBuffer example.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/heapbytebuffer.zip\"><strong>Java Nio HeapByteBuffer example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and for good reason, it&#8217;s package private. Although it&#8217;s use is almost guaranteed when working with ByteBuffers unless you opt for a DirectByteBuffer (off heap). By virtue of extending ByteBuffer, it&nbsp;also &hellip;<\/p>\n","protected":false},"author":129,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[1043],"class_list":["post-48093","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nio","tag-nio"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Nio HeapByteBuffer Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Nio HeapByteBuffer Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-29T08:00:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-12T09:27:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"JJ\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jeanjayvester1\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"JJ\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/\"},\"author\":{\"name\":\"JJ\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/af856abe55325eb35866dc62a821c1bc\"},\"headline\":\"Java Nio HeapByteBuffer Example\",\"datePublished\":\"2017-06-29T08:00:29+00:00\",\"dateModified\":\"2019-03-12T09:27:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/\"},\"wordCount\":611,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"nio\"],\"articleSection\":[\"nio\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/\",\"name\":\"Java Nio HeapByteBuffer Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2017-06-29T08:00:29+00:00\",\"dateModified\":\"2019-03-12T09:27:49+00:00\",\"description\":\"This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"nio\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/nio\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Java Nio HeapByteBuffer Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/af856abe55325eb35866dc62a821c1bc\",\"name\":\"JJ\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9c7eb5a98aedd6421eb285eea1b5e8991789024a35e415108b292edb81a37c3f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9c7eb5a98aedd6421eb285eea1b5e8991789024a35e415108b292edb81a37c3f?s=96&d=mm&r=g\",\"caption\":\"JJ\"},\"description\":\"Jean-Jay Vester graduated from the Cape Peninsula University of Technology, Cape Town, in 2001 and has spent most of his career developing Java backend systems for small to large sized companies both sides of the equator. He has an abundance of experience and knowledge in many varied Java frameworks and has also acquired some systems knowledge along the way. Recently he has started developing his JavaScript skill set specifically targeting Angularjs and also bridged that skill to the backend with Nodejs.\",\"sameAs\":[\"http:\/\/examples.javacodegeeks.com\/\",\"https:\/\/za.linkedin.com\/in\/jean-jay-vester-b135906\",\"https:\/\/x.com\/jeanjayvester1\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/jean-vester\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Nio HeapByteBuffer Example - Java Code Geeks","description":"This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/","og_locale":"en_US","og_type":"article","og_title":"Java Nio HeapByteBuffer Example - Java Code Geeks","og_description":"This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-06-29T08:00:29+00:00","article_modified_time":"2019-03-12T09:27:49+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"JJ","twitter_card":"summary_large_image","twitter_creator":"@jeanjayvester1","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"JJ","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/"},"author":{"name":"JJ","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/af856abe55325eb35866dc62a821c1bc"},"headline":"Java Nio HeapByteBuffer Example","datePublished":"2017-06-29T08:00:29+00:00","dateModified":"2019-03-12T09:27:49+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/"},"wordCount":611,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["nio"],"articleSection":["nio"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/","name":"Java Nio HeapByteBuffer Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2017-06-29T08:00:29+00:00","dateModified":"2019-03-12T09:27:49+00:00","description":"This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/nio\/java-nio-heapbytebuffer-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"nio","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/nio\/"},{"@type":"ListItem","position":5,"name":"Java Nio HeapByteBuffer Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/af856abe55325eb35866dc62a821c1bc","name":"JJ","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9c7eb5a98aedd6421eb285eea1b5e8991789024a35e415108b292edb81a37c3f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9c7eb5a98aedd6421eb285eea1b5e8991789024a35e415108b292edb81a37c3f?s=96&d=mm&r=g","caption":"JJ"},"description":"Jean-Jay Vester graduated from the Cape Peninsula University of Technology, Cape Town, in 2001 and has spent most of his career developing Java backend systems for small to large sized companies both sides of the equator. He has an abundance of experience and knowledge in many varied Java frameworks and has also acquired some systems knowledge along the way. Recently he has started developing his JavaScript skill set specifically targeting Angularjs and also bridged that skill to the backend with Nodejs.","sameAs":["http:\/\/examples.javacodegeeks.com\/","https:\/\/za.linkedin.com\/in\/jean-jay-vester-b135906","https:\/\/x.com\/jeanjayvester1"],"url":"https:\/\/examples.javacodegeeks.com\/author\/jean-vester\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/48093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/129"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=48093"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/48093\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=48093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=48093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=48093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}