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


Java Charsets.UTF_8屬性代碼示例

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


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

示例1: extractRequestEntity

static String extractRequestEntity(ContainerRequestContext request) {
    if (request.hasEntity()) {
        InputStream inputStreamOriginal = request.getEntityStream();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStreamOriginal, MAX_ENTITY_READ);
        bufferedInputStream.mark(MAX_ENTITY_READ);
        byte[] bytes = new byte[MAX_ENTITY_READ];
        int read;
        try {
            read = bufferedInputStream.read(bytes, 0, MAX_ENTITY_READ);
            bufferedInputStream.reset();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        request.setEntityStream(bufferedInputStream);

        return new String(bytes, Charsets.UTF_8);
    }
    return null;
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:19,代碼來源:ServerLogFilter.java

示例2: readLine

private String readLine() throws IOException {

        ByteArrayDataOutput out = ByteStreams.newDataOutput(300);
        int i = 0;
        int c;
        while ((c = raf.read()) != -1) {
            i++;
            out.write((byte) c);
            if (c == LINE_SEP.charAt(0)) {
                break;
            }
        }
        if (i == 0) {
            return null;
        }
        return new String(out.toByteArray(), Charsets.UTF_8);
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:17,代碼來源:TailFile.java

示例3: getConfResourceAsReader

/** 
 * Get a {@link Reader} attached to the configuration resource with the
 * given <code>name</code>.
 * 
 * @param name configuration resource name.
 * @return a reader attached to the resource.
 */
public Reader getConfResourceAsReader(String name) {
  try {
    URL url= getResource(name);

    if (url == null) {
      LOG.info(name + " not found");
      return null;
    } else {
      LOG.info("found resource " + name + " at " + url);
    }

    return new InputStreamReader(url.openStream(), Charsets.UTF_8);
  } catch (Exception e) {
    return null;
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:23,代碼來源:Configuration.java

示例4: write

@Override
public void write(final ArgumentOutput output) throws IOException {
  final File f = new File(directory, output.docId().toString());
  final PrintWriter out = new PrintWriter(new BufferedWriter(
      new OutputStreamWriter(new FileOutputStream(f), Charsets.UTF_8)));

  try {
    for (final Response response : format.responseOrdering().sortedCopy(output.responses())) {
      final String metadata = output.metadata(response);
      if (!metadata.equals(ArgumentOutput.DEFAULT_METADATA)) {
        out.print(METADATA_MARKER + metadata + "\n");
      }
      //out.print(response.responseID());
      out.print(format.identifierField(response));
      out.print("\t");
      final double confidence = output.confidence(response);
      out.print(argToString(response, confidence) + "\n");
    }
  } finally {
    out.close();
  }
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:22,代碼來源:AssessmentSpecFormats.java

示例5: testReconfigure

@Test
public void testReconfigure() throws InterruptedException, IOException {
  final int NUM_RECONFIGS = 20;
  for (int i = 0; i < NUM_RECONFIGS; i++) {
    Context context = new Context();
    File file = new File(tmpDir.getAbsolutePath() + "/file-" + i);
    Files.write("File " + i, file, Charsets.UTF_8);
    context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
        tmpDir.getAbsolutePath());
    Configurables.configure(source, context);
    source.start();
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    Transaction txn = channel.getTransaction();
    txn.begin();
    try {
      Event event = channel.take();
      String content = new String(event.getBody(), Charsets.UTF_8);
      Assert.assertEquals("File " + i, content);
      txn.commit();
    } catch (Throwable t) {
      txn.rollback();
    } finally {
      txn.close();
    }
    source.stop();
    Assert.assertFalse("Fatal error on iteration " + i, source.hasFatalError());
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:28,代碼來源:TestSpoolDirectorySource.java

示例6: readBackupFromResource

private String readBackupFromResource(final String filename) throws IOException {
    final BufferedReader reader = new BufferedReader(
            new InputStreamReader(getClass().getResourceAsStream(filename), Charsets.UTF_8));
    final StringBuilder backup = new StringBuilder();
    Io.copy(reader, backup);
    reader.close();

    return backup.toString();
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:9,代碼來源:CryptoTest.java

示例7: readFile

List<String> readFile(String filename) throws IOException {
  List<String> result = new ArrayList<String>(10000);
  BufferedReader in = new BufferedReader(
      new InputStreamReader(new FileInputStream(filename), Charsets.UTF_8));
  String line = in.readLine();
  while (line != null) {
    result.add(line);
    line = in.readLine();
  }
  in.close();
  return result;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:12,代碼來源:TeraScheduler.java

示例8: writePropertiesFile

void writePropertiesFile(FileSystem fs, Path path) throws IOException {
  Properties p = new Properties();
  p.setProperty("table", tableName);
  if (families != null) {
    p.setProperty("columnFamilies", families);
  }
  p.setProperty("targetBatchSize", Long.toString(batchSize));
  p.setProperty("numHashFiles", Integer.toString(numHashFiles));
  if (!isTableStartRow(startRow)) {
    p.setProperty("startRowHex", Bytes.toHex(startRow));
  }
  if (!isTableEndRow(stopRow)) {
    p.setProperty("stopRowHex", Bytes.toHex(stopRow));
  }
  if (scanBatch > 0) {
    p.setProperty("scanBatch", Integer.toString(scanBatch));
  }
  if (versions >= 0) {
    p.setProperty("versions", Integer.toString(versions));
  }
  if (startTime != 0) {
    p.setProperty("startTimestamp", Long.toString(startTime));
  }
  if (endTime != 0) {
    p.setProperty("endTimestamp", Long.toString(endTime));
  }
  
  try (OutputStreamWriter osw = new OutputStreamWriter(fs.create(path), Charsets.UTF_8)) {
    p.store(osw, null);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:31,代碼來源:HashTable.java

示例9: assertThat

public static ParserAssert assertThat(LexerlessGrammarBuilder b, GrammarRuleKey rule) {
    return new ParserAssert(new ActionParser<Tree>(
            Charsets.UTF_8,
            b,
            OneCGrammar.class,
            new TreeFactory(),
            new OneCNodeBuilder(),
            rule));
}
 
開發者ID:antowski,項目名稱:sonar-onec,代碼行數:9,代碼來源:Assertions.java

示例10: init

@Override
public void init(Properties config, ServletContext servletContext,
                 long tokenValidity) throws Exception {

  String signatureSecretFile = config.getProperty(
      AuthenticationFilter.SIGNATURE_SECRET_FILE, null);

  Reader reader = null;
  if (signatureSecretFile != null) {
    try {
      StringBuilder sb = new StringBuilder();
      reader = new InputStreamReader(
          new FileInputStream(signatureSecretFile), Charsets.UTF_8);
      int c = reader.read();
      while (c > -1) {
        sb.append((char) c);
        c = reader.read();
      }
      secret = sb.toString().getBytes(Charset.forName("UTF-8"));
    } catch (IOException ex) {
      throw new RuntimeException("Could not read signature secret file: " +
          signatureSecretFile);
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          // nothing to do
        }
      }
    }
  }

  secrets = new byte[][]{secret};
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:FileSignerSecretProvider.java

示例11: readStringFromBuffer

/**
 * Reads a string from this buffer. Expected parameter is maximum allowed string length. Will throw IOException if
 * string length exceeds this value!
 */
public String readStringFromBuffer(int maxLength)
{
    int i = this.readVarIntFromBuffer();

    if (i > maxLength * 4)
    {
        throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + i + " > " + maxLength * 4 + ")");
    }
    else if (i < 0)
    {
        throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!");
    }
    else
    {
        String s = new String(this.readBytes(i).array(), Charsets.UTF_8);

        if (s.length() > maxLength)
        {
            throw new DecoderException("The received string length is longer than maximum allowed (" + i + " > " + maxLength + ")");
        }
        else
        {
            return s;
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:30,代碼來源:PacketBuffer.java

示例12: testTempFiles

public void testTempFiles() throws Exception {
  String fileName = storage.uploadTempFile("test\n".getBytes(Charsets.UTF_8));
  BufferedReader reader = new BufferedReader(new InputStreamReader(storage.openTempFile(fileName),
      Charsets.UTF_8));
  assertTrue(reader.readLine().equals("test"));
  storage.deleteTempFile(fileName);
  try {
    storage.deleteTempFile("frob"); // Should fail because doesn't start with __TEMP__
    fail();
  } catch (Exception e) {
    assertTrue(e instanceof RuntimeException);
  }
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:13,代碼來源:ObjectifyStorageIoTest.java

示例13: put

private EtcdResult put(String key, List<BasicNameValuePair> data, Map<String, String> params, int[] expectedHttpStatusCodes,
            int... expectedErrorCodes) throws EtcdClientException {
    URI uri = buildUriWithKeyAndParams(key, params);
    HttpPut httpPut = new HttpPut(uri);

    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(data, Charsets.UTF_8);
    httpPut.setEntity(entity);

    return syncExecute(httpPut, expectedHttpStatusCodes, expectedErrorCodes);
}
 
開發者ID:kevin-xu-158,項目名稱:JavaNRPC,代碼行數:10,代碼來源:EtcdClient.java

示例14: assertOutputMatches

private void assertOutputMatches(String string) {
  String errOutput = new String(out.toByteArray(), Charsets.UTF_8);
  String output = new String(out.toByteArray(), Charsets.UTF_8);

  if (!errOutput.matches(string) && !output.matches(string)) {
    fail("Expected output to match '" + string +
        "' but err_output was:\n" + errOutput +
        "\n and output was: \n" + output);
  }

  out.reset();
  err.reset();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:13,代碼來源:TestDFSAdminWithHA.java

示例15: onFileInit

@Override
public void onFileInit(Path file) {
    if (logger.isTraceEnabled()) {
        logger.trace("Loading script file : [{}]", file);
    }
    Tuple<String, String> scriptNameExt = scriptNameExt(file);
    if (scriptNameExt != null) {
        ScriptEngineService engineService = getScriptEngineServiceForFileExt(scriptNameExt.v2());
        if (engineService == null) {
            logger.warn("no script engine found for [{}]", scriptNameExt.v2());
        } else {
            try {
                //we don't know yet what the script will be used for, but if all of the operations for this lang
                // with file scripts are disabled, it makes no sense to even compile it and cache it.
                if (isAnyScriptContextEnabled(engineService.types()[0], engineService, ScriptType.FILE)) {
                    logger.info("compiling script file [{}]", file.toAbsolutePath());
                    try(InputStreamReader reader = new InputStreamReader(Files.newInputStream(file), Charsets.UTF_8)) {
                        String script = Streams.copyToString(reader);
                        CacheKey cacheKey = new CacheKey(engineService, scriptNameExt.v1(), null, Collections.<String, String>emptyMap());
                        staticCache.put(cacheKey, new CompiledScript(ScriptType.FILE, scriptNameExt.v1(), engineService.types()[0], engineService.compile(script, Collections.<String, String>emptyMap())));
                        scriptMetrics.onCompilation();
                    }
                } else {
                    logger.warn("skipping compile of script file [{}] as all scripted operations are disabled for file scripts", file.toAbsolutePath());
                }
            } catch (Throwable e) {
                logger.warn("failed to load/compile script [{}]", e, scriptNameExt.v1());
            }
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:31,代碼來源:ScriptService.java


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