Package java.nio

Examples of java.nio.IntBuffer


        id = int_buffer.get(0);
    }

    @Override
    public void destroy() {
        IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
        int_buffer.put(id);
        ARBVertexBufferObject.glDeleteBuffersARB(int_buffer);
    }
View Full Code Here


            byte b = mmb.get();
            assertEquals("Got wrong byte value", (byte) 'A' + i, b); //$NON-NLS-1$
        }

        // Now convert to an IntBuffer to read our ints
        IntBuffer ibuffer = mmb.asIntBuffer();
        for (int i = 0; i < 5; i++) {
            int val = ibuffer.get();
            assertEquals("Got wrong int value", i + 1, val); //$NON-NLS-1$
        }
        fc.close();
    }
View Full Code Here

        }
    }

    protected void write(FileChannel channel, EntryArray ea) throws IOException {
        ByteBuffer b = IOUtils.allocate(ea.getSize() * IOUtils.INT_SIZE);
        IntBuffer ib = b.asIntBuffer();
        for (int i = 0; i < ea.getSize(); i++) {
            ib.put(ea.getEntry(i));
        }
        ib.rewind();
        channel.write(b);
    }
View Full Code Here

        ib.rewind();
        channel.write(b);
    }

    protected int[] readEntries(RandomAccessFile raf, int nbEntries) throws IOException {
        IntBuffer bb = IOUtils.getByteBuffer(raf, nbEntries * IOUtils.INT_SIZE).asIntBuffer();

        int[] entries = new int[nbEntries];
        for (int entryNumber = 0; entryNumber < nbEntries; entryNumber++) {
            int entry = bb.get();
            if (entry > 0) {
                LOG.debug("readEntries: entry[" + entryNumber + "]=" + entry);
            }
            entries[entryNumber] = entry;
        }
View Full Code Here

        return segment + "_" + term;
    }

    public byte[] getPostings() {
        ByteBuffer bytes = ByteBuffer.allocate(doccount * 4);
        IntBuffer ib = bytes.asIntBuffer();
        ib.put(docs.ints, 0, doccount);
        return bytes.array();
    }
View Full Code Here

                String key = segment + "_" + add.text();
                if (!redis.exists(key)) {
                    // New key - just add it with the current bitset
                    //int[] docset = new int[docs.cardinality()];
                    ByteBuffer bytes = ByteBuffer.allocate(docs.cardinality() * 4);
                    IntBuffer docset = bytes.asIntBuffer();
                    for (int i = docs.nextSetBit(0), j = 0; i >= 0; i = docs.nextSetBit(i + 1), j++) {
                        docset.put(j, i);
                    }
                    redis.set(key, bytes.array());
                }
                else {
                    byte[] orig = redis.get(key);
View Full Code Here

  /** Bulk input of an int array. */
  public int[] readInts (int length) throws KryoException {
    if (capacity - position >= length * 4 && isNativeOrder()) {
      int[] array = new int[length];
      IntBuffer buf = niobuffer.asIntBuffer();
      buf.get(array);
      position += length * 4;
      niobuffer.position(position);
      return array;
    } else
      return super.readInts(length);
View Full Code Here

  // Methods implementing bulk operations on arrays of primitive types

  /** Bulk output of an int array. */
  public void writeInts (int[] object) throws KryoException {
    if (capacity - position >= object.length * 4 && isNativeOrder()) {
      IntBuffer buf = niobuffer.asIntBuffer();
      buf.put(object);
      position += object.length * 4;
    } else
      super.writeInts(object);
  }
View Full Code Here

   * @param data - the integer array with the data.
   * @return An equivalent byte array.
   */
  private static byte[] toByteArray(int[] data) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 4);       
        IntBuffer intBuffer = byteBuffer.asIntBuffer();
       
        intBuffer.put(data);
        return byteBuffer.array();
  }
View Full Code Here

   * Note that the number of byte elements are only perserved if the byte size is a multiple of four.
   * @param data - the byte array to convert.
   * @return The equivalent integer array.
   */
  private static int[] toIntegerArray(byte[] data) {
    IntBuffer source = ByteBuffer.wrap(data).asIntBuffer();
    IntBuffer copy = IntBuffer.allocate(source.capacity());
   
    copy.put(source);
    return copy.array();
  }
View Full Code Here

TOP

Related Classes of java.nio.IntBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.