當前位置: 首頁>>代碼示例>>Java>>正文


Java Charsets.UTF_16屬性代碼示例

本文整理匯總了Java中com.google.common.base.Charsets.UTF_16屬性的典型用法代碼示例。如果您正苦於以下問題:Java Charsets.UTF_16屬性的具體用法?Java Charsets.UTF_16怎麽用?Java Charsets.UTF_16使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.google.common.base.Charsets的用法示例。


在下文中一共展示了Charsets.UTF_16屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toStringFromUTF16

public static String toStringFromUTF16(int start, int end, DrillBuf buffer) {
  byte[] buf = new byte[end - start];
  buffer.getBytes(start, buf, 0, end - start);
  return new String(buf, Charsets.UTF_16);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:5,代碼來源:StringFunctionHelpers.java

示例2: testGenericUDF

@Test
public void testGenericUDF() throws Throwable {

  int numRecords = 0;
  String planString = Resources.toString(Resources.getResource("functions/hive/GenericUDF.json"), Charsets.UTF_8);
  List<QueryDataBatch> results = testPhysicalWithResults(planString);

  RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
  for (QueryDataBatch result : results) {
    batchLoader.load(result.getHeader().getDef(), result.getData());
    if (batchLoader.getRecordCount() <= 0) {
      result.release();
      batchLoader.clear();
      continue;
    }
    // Output columns and types
    //  1. str1 : Var16Char
    //  2. upperStr1 : NullableVar16Char
    //  3. concat : NullableVarChar
    //  4. flt1 : Float4
    //  5. format_number : NullableFloat8
    //  6. nullableStr1 : NullableVar16Char
    //  7. upperNullableStr1 : NullableVar16Char
    Var16CharVector str1V = (Var16CharVector) batchLoader.getValueAccessorById(Var16CharVector.class, 0).getValueVector();
    NullableVar16CharVector upperStr1V = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 1).getValueVector();
    NullableVar16CharVector concatV = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 2).getValueVector();
    Float4Vector flt1V = (Float4Vector) batchLoader.getValueAccessorById(Float4Vector.class, 3).getValueVector();
    NullableVar16CharVector format_numberV = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 4).getValueVector();
    NullableVar16CharVector nullableStr1V = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 5).getValueVector();
    NullableVar16CharVector upperNullableStr1V = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 6).getValueVector();

    for (int i=0; i<batchLoader.getRecordCount(); i++) {
      String in = new String(str1V.getAccessor().get(i), Charsets.UTF_16);
      String upper = new String(upperStr1V.getAccessor().get(i), Charsets.UTF_16);
      assertTrue(in.toUpperCase().equals(upper));


      String concat = new String(concatV.getAccessor().get(i), Charsets.UTF_16);
      assertTrue(concat.equals(in+"-"+in));

      float flt1 = flt1V.getAccessor().get(i);
      String format_number = new String(format_numberV.getAccessor().get(i), Charsets.UTF_16);


      String nullableStr1 = null;
      if (!nullableStr1V.getAccessor().isNull(i)) {
        nullableStr1 = new String(nullableStr1V.getAccessor().get(i), Charsets.UTF_16);
      }

      String upperNullableStr1 = null;
      if (!upperNullableStr1V.getAccessor().isNull(i)) {
        upperNullableStr1 = new String(upperNullableStr1V.getAccessor().get(i), Charsets.UTF_16);
      }

      assertEquals(nullableStr1 != null, upperNullableStr1 != null);
      if (nullableStr1 != null) {
        assertEquals(nullableStr1.toUpperCase(), upperNullableStr1);
      }

      System.out.println(in + ", " + upper + ", " + concat + ", " +
        flt1 + ", " + format_number + ", " + nullableStr1 + ", " + upperNullableStr1);

      numRecords++;
    }

    result.release();
    batchLoader.clear();
  }

  System.out.println("Processed " + numRecords + " records");
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:71,代碼來源:TestHiveUDFs.java

示例3: testUDF

@Test
public void testUDF() throws Throwable {
  int numRecords = 0;
  String planString = Resources.toString(Resources.getResource("functions/hive/UDF.json"), Charsets.UTF_8);
  List<QueryDataBatch> results = testPhysicalWithResults(planString);

  RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
  for (QueryDataBatch result : results) {
    batchLoader.load(result.getHeader().getDef(), result.getData());
    if (batchLoader.getRecordCount() <= 0) {
      result.release();
      batchLoader.clear();
      continue;
    }

    // Output columns and types
    // 1. str1 : Var16Char
    // 2. str1Length : Int
    // 3. str1Ascii : Int
    // 4. flt1 : Float4
    // 5. pow : Float8
    Var16CharVector str1V = (Var16CharVector) batchLoader.getValueAccessorById(Var16CharVector.class, 0).getValueVector();
    NullableIntVector str1LengthV = (NullableIntVector) batchLoader.getValueAccessorById(NullableIntVector.class, 1).getValueVector();
    NullableIntVector str1AsciiV = (NullableIntVector) batchLoader.getValueAccessorById(NullableIntVector.class, 2).getValueVector();
    Float4Vector flt1V = (Float4Vector) batchLoader.getValueAccessorById(Float4Vector.class, 3).getValueVector();
    NullableFloat8Vector powV = (NullableFloat8Vector) batchLoader.getValueAccessorById(NullableFloat8Vector.class, 4).getValueVector();

    for (int i=0; i<batchLoader.getRecordCount(); i++) {
      String str1 = new String(str1V.getAccessor().get(i), Charsets.UTF_16);
      int str1Length = str1LengthV.getAccessor().get(i);
      assertTrue(str1.length() == str1Length);

      int str1Ascii = str1AsciiV.getAccessor().get(i);

      float flt1 = flt1V.getAccessor().get(i);

      double pow = 0;
      if (!powV.getAccessor().isNull(i)) {
        pow = powV.getAccessor().get(i);
        assertTrue(Math.pow(flt1, 2.0) == pow);
      }

      System.out.println(str1 + ", " + str1Length + ", " + str1Ascii + ", " + flt1 + ", " + pow);
      numRecords++;
    }

    result.release();
    batchLoader.clear();
  }

  System.out.println("Processed " + numRecords + " records");
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:52,代碼來源:TestHiveUDFs.java

示例4: toStringFromUTF16

public static String toStringFromUTF16(int start, int end, ArrowBuf buffer) {
  byte[] buf = new byte[end - start];
  buffer.getBytes(start, buf, 0, end - start);
  return new String(buf, Charsets.UTF_16);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:5,代碼來源:StringFunctionHelpers.java


注:本文中的com.google.common.base.Charsets.UTF_16屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。