Package java.nio

Examples of java.nio.ByteBuffer.array()


  // convert char array to byte array, assuming UTF-8 encoding
  static protected byte[] convertCharToByteUTF(char[] from) {
    Charset c = Charset.forName("UTF-8");
    ByteBuffer output = c.encode(CharBuffer.wrap(from));
    return output.array();
  }

  //////////////////////////////////////////////////////////////////////////////////////
  // create new file
View Full Code Here


  private Attribute readOpaqueAttValues(int grpid, int varid, String attname, int len, UserType userType) throws IOException {
    int total = len * userType.size;
    ByteBuffer bb = ByteBuffer.allocate(total);
    int ret = nc4.nc_get_att(grpid, varid, attname, bb);
    if (ret != 0) throw new IOException(nc4.nc_strerror(ret));
    return new Attribute(attname, Array.factory(DataType.BYTE, new int[] {total}, bb.array()));
  }

  /////////////////////////////////////////////////////////////////////////////

  private void makeVariables(int grpid, Group g) throws IOException {
View Full Code Here

    int ret;

    ByteBuffer bb = ByteBuffer.allocate(len*size);
    ret = nc4.nc_get_var(grpid, varid, bb);
    if (ret != 0) throw new IOException(nc4.nc_strerror(ret));
    byte[] entire = bb.array();

    ArrayObject values = new ArrayObject(ByteBuffer.class, new int[]{len});
    int count = 0;
    IndexIterator ii = values.getIndexIterator();
    while (ii.hasNext()) {
View Full Code Here

    if (ret != 0) throw new IOException(nc4.nc_strerror(ret));

    switch (baseType) {
      case NCLibrary.NC_BYTE:
      case NCLibrary.NC_UBYTE:
        return Array.factory( DataType.BYTE.getPrimitiveClassType(), shape, bb.array());

      case NCLibrary.NC_SHORT:
      case NCLibrary.NC_USHORT:
        ShortBuffer sb = bb.asShortBuffer();
        return Array.factory( DataType.BYTE.getPrimitiveClassType(), shape, sb.array());
View Full Code Here

  private void writeString(String s, DataOutputStream dataOut)
    throws IOException
  {
    ByteBuffer byteBuf = charsetEncoder.encode(CharBuffer.wrap(s));
    dataOut.writeInt(byteBuf.remaining());
    dataOut.write(byteBuf.array(), 0, byteBuf.remaining());
  }

  private String readString(DataInputStream dataIn)
    throws IOException
  {
View Full Code Here

          // heres a way to get a byte array for CRC from other values we need for duplicate checking
          ByteBuffer bb = ByteBuffer.allocate(12);
          bb.putInt( product.getDiscipline());
          bb.putLong( product.getRefTime());
          crc32.update(bb.array());

          long crcv = crc32.getValue();
          Integer recnum = pdsMap.get(crcv);
          // duplicate found
          if ( recnum != null) {
View Full Code Here

          crc32.reset();
          crc32.update( rr.pdsData );
          ByteBuffer bb = ByteBuffer.allocate(12);
          bb.putInt( rr.discipline );
          bb.putLong( rr.refTime );
          crc32.update(bb.array());
          pdsMap.put( crc32.getValue(), i );
        }
        Calendar cal = Calendar.getInstance();
        // now check new records for duplicates, assumes original index has no duplicates
        for (int i = 0; i < products.size(); i++) {
View Full Code Here

          crc32.reset();
          crc32.update(product.getPDS().getPdsVars().getPDSBytes());
          ByteBuffer bb = ByteBuffer.allocate(12);
          bb.putInt( product.getDiscipline());
          bb.putLong( product.getRefTime());
          crc32.update(bb.array());

          long crcv = crc32.getValue();
          Integer recnum = pdsMap.get(crcv);
          // duplicate found
          if ( recnum != null) {
View Full Code Here

          Grib1Product product = products.get( i );
          crc32.reset();
          crc32.update(product.getPDS().getPdsVars().getPDSBytes());
          ByteBuffer bb = ByteBuffer.allocate(8);
          bb.putLong( product.getPDS().getPdsVars().getReferenceTime());
          crc32.update(bb.array());

          long crcv = crc32.getValue();
          Integer recnum = pdsMap.get(crcv);
          // duplicate found
          if ( recnum != null ) {
View Full Code Here

          Grib2WriteIndex.RawRecord rr = recordList.get( i );
          crc32.reset();
          crc32.update( rr.pdsData );
          ByteBuffer bb = ByteBuffer.allocate(8);
          bb.putLong( rr.refTime );
          crc32.update(bb.array());
          pdsMap.put( crc32.getValue(), i );
        }
        // now check new records for duplicates, assumes original index has no duplicates
        for (int i = 0; i < products.size(); i++) {
          Grib1Product product = products.get( i );
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.