Java 类org.apache.commons.io.Charsets 实例源码

项目:Backmemed    文件:Lang.java   
public static void loadLocaleData(InputStream p_loadLocaleData_0_, Map p_loadLocaleData_1_) throws IOException
{
    for (String s : IOUtils.readLines(p_loadLocaleData_0_, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])((String[])Iterables.toArray(splitter.split(s), String.class));

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = pattern.matcher(astring[1]).replaceAll("%$1s");
                p_loadLocaleData_1_.put(s1, s2);
            }
        }
    }
}
项目:hadoop-oss    文件:Display.java   
@Override
public int read() throws IOException {
  int ret;
  if (null == inbuf || -1 == (ret = inbuf.read())) {
    if (!r.next(key, val)) {
      return -1;
    }
    byte[] tmp = key.toString().getBytes(Charsets.UTF_8);
    outbuf.write(tmp, 0, tmp.length);
    outbuf.write('\t');
    tmp = val.toString().getBytes(Charsets.UTF_8);
    outbuf.write(tmp, 0, tmp.length);
    outbuf.write('\n');
    inbuf.reset(outbuf.getData(), outbuf.getLength());
    outbuf.reset();
    ret = inbuf.read();
  }
  return ret;
}
项目:hadoop-oss    文件:HtmlQuoting.java   
/**
 * Quote the given item to make it html-safe.
 * @param item the string to quote
 * @return the quoted string
 */
public static String quoteHtmlChars(String item) {
  if (item == null) {
    return null;
  }
  byte[] bytes = item.getBytes(Charsets.UTF_8);
  if (needsQuoting(bytes, 0, bytes.length)) {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try {
      quoteHtmlChars(buffer, bytes, 0, bytes.length);
      return buffer.toString("UTF-8");
    } catch (IOException ioe) {
      // Won't happen, since it is a bytearrayoutputstream
      return null;
    }
  } else {
    return item;
  }
}
项目:Backmemed    文件:Locale.java   
private void loadLocaleData(InputStream inputStreamIn) throws IOException
{
    for (String s : IOUtils.readLines(inputStreamIn, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(SPLITTER.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = PATTERN.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
项目:careconnect-reference-implementation    文件:SNOMEDUKMockValidationSupport.java   
private void loadStructureDefinitions(FhirContext theContext, Map<String, StructureDefinition> theCodeSystems, String theClasspath) {
  logD("SNOMEDMOCK Loading structure definitions from classpath: "+ theClasspath);
  InputStream valuesetText = SNOMEDUKMockValidationSupport.class.getResourceAsStream(theClasspath);
  if (valuesetText != null) {
    InputStreamReader reader = new InputStreamReader(valuesetText, Charsets.UTF_8);

    Bundle bundle = theContext.newXmlParser().parseResource(Bundle.class, reader);
    for (BundleEntryComponent next : bundle.getEntry()) {
      if (next.getResource() instanceof StructureDefinition) {
        StructureDefinition nextSd = (StructureDefinition) next.getResource();
        nextSd.getText().setDivAsString("");
        String system = nextSd.getUrl();
        if (isNotBlank(system)) {
          theCodeSystems.put(system, nextSd);
        }
      }
    }
  } else {
    log.warn("Unable to load resource: {}", theClasspath);
  }
}
项目:hadoop-oss    文件:TestGangliaMetrics.java   
private void checkMetrics(List<byte[]> bytearrlist, int expectedCount) {
  boolean[] foundMetrics = new boolean[expectedMetrics.length];
  for (byte[] bytes : bytearrlist) {
    String binaryStr = new String(bytes, Charsets.UTF_8);
    for (int index = 0; index < expectedMetrics.length; index++) {
      if (binaryStr.indexOf(expectedMetrics[index]) >= 0) {
        foundMetrics[index] = true;
        break;
      }
    }
  }

  for (int index = 0; index < foundMetrics.length; index++) {
    if (!foundMetrics[index]) {
      assertTrue("Missing metrics: " + expectedMetrics[index], false);
    }
  }

  assertEquals("Mismatch in record count: ",
      expectedCount, bytearrlist.size());
}
项目:TOSCAna    文件:AbstractLifecycle.java   
private void setUpDirectories(PluginFileAccess access) throws IOException {
    access.createDirectories(UTIL_DIR_PATH);

    //Iterate over all files in the script list
    List<String> files = IOUtils.readLines(
        getClass().getResourceAsStream(RESOURCE_PATH_BASE + "scripts-list"),
        Charsets.UTF_8
    );
    for (String line : files) {
        if (!line.isEmpty()) {
            //Copy the file into the desired directory
            InputStreamReader input = new InputStreamReader(
                getClass().getResourceAsStream(RESOURCE_PATH_BASE + line)
            );
            BufferedWriter output = access.access(UTIL_DIR_PATH + line);
            IOUtils.copy(input, output);
            input.close();
            output.close();
        }
    }
}
项目:CustomWorldGen    文件:Locale.java   
private void loadLocaleData(InputStream inputStreamIn) throws IOException
{
    inputStreamIn = net.minecraftforge.fml.common.FMLCommonHandler.instance().loadLanguage(properties, inputStreamIn);
    if (inputStreamIn == null) return;
    for (String s : IOUtils.readLines(inputStreamIn, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(SPLITTER.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = PATTERN.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
项目:DecompiledMinecraft    文件:Locale.java   
private void loadLocaleData(InputStream p_135021_1_) throws IOException
{
    for (String s : IOUtils.readLines(p_135021_1_, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(splitter.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = pattern.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
项目:BaseClient    文件:Lang.java   
public static void loadLocaleData(InputStream p_loadLocaleData_0_, Map p_loadLocaleData_1_) throws IOException
{
    for (String s : IOUtils.readLines(p_loadLocaleData_0_, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])((String[])Iterables.toArray(splitter.split(s), String.class));

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = pattern.matcher(astring[1]).replaceAll("%$1s");
                p_loadLocaleData_1_.put(s1, s2);
            }
        }
    }
}
项目:BaseClient    文件:Locale.java   
private void loadLocaleData(InputStream p_135021_1_) throws IOException
{
    for (String s : IOUtils.readLines(p_135021_1_, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(splitter.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = pattern.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
项目:BaseClient    文件:Locale.java   
private void loadLocaleData(InputStream p_135021_1_) throws IOException
{
    for (String s : IOUtils.readLines(p_135021_1_, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(splitter.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = pattern.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
项目:laozhongyi    文件:HyperParameterConfig.java   
private Map<String, String> toMap() {
    final File file = new File(mConfigFilePath);
    List<String> lines;
    try {
        lines = FileUtils.readLines(file, Charsets.UTF_8);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
    final Map<String, String> map = Maps.newTreeMap();
    for (final String line : lines) {
        final String[] segs = StringUtils.split(line, " = ");
        map.put(segs[0], segs[1]);
    }

    return map;
}
项目:laozhongyi    文件:HyperParameterScopeConfigReader.java   
public static List<HyperParameterScopeItem> read(final String configFilePath) {
    final File file = new File(configFilePath);
    List<String> lines;
    try {
        lines = FileUtils.readLines(file, Charsets.UTF_8);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
    final List<HyperParameterScopeItem> result = Lists.newArrayList();
    for (final String line : lines) {
        final String[] segments = StringUtils.split(line, ',');
        final List<String> values = Lists.newArrayList();
        for (int i = 1; i < segments.length; ++i) {
            values.add(segments[i]);
        }
        final HyperParameterScopeItem item = new HyperParameterScopeItem(segments[0], values);
        result.add(item);
    }
    return result;
}
项目:gitplex-mit    文件:QuickSearchPanel.java   
private void storeRecentOpened(String blobPath) {
    List<String> recentOpened = getRecentOpened();
    recentOpened.remove(blobPath);
    recentOpened.add(0, blobPath);
    while (recentOpened.size() > MAX_RECENT_OPENED)
        recentOpened.remove(recentOpened.size()-1);
    String encoded;
    try {
        encoded = URLEncoder.encode(Joiner.on("\n").join(recentOpened), Charsets.UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    Cookie cookie = new Cookie(COOKIE_RECENT_OPENED, encoded);
    cookie.setMaxAge(Integer.MAX_VALUE);
    WebResponse response = (WebResponse) RequestCycle.get().getResponse();
    response.addCookie(cookie);
}
项目:ijcnlp2017-cmaps    文件:FeatureExtractor.java   
private Map<Integer, Map<String, Double>> loadGraphFeatures(int topic) {
    // concept -> feature_name -> value
    Map<Integer, Map<String, Double>> data = new HashMap<Integer, Map<String, Double>>();
    String fileName = this.baseFolder + "/" + topic + "/" + this.graphFile;
    try {
        List<String> lines = FileUtils.readLines(new File(fileName), Charsets.UTF_8);
        String[] header = lines.get(0).split("\t");
        for (String line : lines.subList(1, lines.size())) {
            String[] cols = line.split("\t");
            int id = Integer.parseInt(cols[0]);
            Map<String, Double> features = new HashMap<String, Double>();
            for (int i = 1; i < cols.length; i++)
                features.put(header[i], Double.parseDouble(cols[i]));
            data.put(id, features);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return data;
}
项目:hadoop    文件:FSDirMkdirOp.java   
/**
 * For a given absolute path, create all ancestors as directories along the
 * path. All ancestors inherit their parent's permission plus an implicit
 * u+wx permission. This is used by create() and addSymlink() for
 * implicitly creating all directories along the path.
 *
 * For example, path="/foo/bar/spam", "/foo" is an existing directory,
 * "/foo/bar" is not existing yet, the function will create directory bar.
 *
 * @return a tuple which contains both the new INodesInPath (with all the
 * existing and newly created directories) and the last component in the
 * relative path. Or return null if there are errors.
 */
static Map.Entry<INodesInPath, String> createAncestorDirectories(
    FSDirectory fsd, INodesInPath iip, PermissionStatus permission)
    throws IOException {
  final String last = new String(iip.getLastLocalName(), Charsets.UTF_8);
  INodesInPath existing = iip.getExistingINodes();
  List<String> children = iip.getPath(existing.length(),
      iip.length() - existing.length());
  int size = children.size();
  if (size > 1) { // otherwise all ancestors have been created
    List<String> directories = children.subList(0, size - 1);
    INode parentINode = existing.getLastINode();
    // Ensure that the user can traversal the path by adding implicit
    // u+wx permission to all ancestor directories
    existing = createChildrenDirectories(fsd, existing, directories,
        addImplicitUwx(parentINode.getPermissionStatus(), permission));
    if (existing == null) {
      return null;
    }
  }
  return new AbstractMap.SimpleImmutableEntry<>(existing, last);
}
项目:hadoop    文件:WebHdfsHandler.java   
private void onGetFileChecksum(ChannelHandlerContext ctx) throws IOException {
  MD5MD5CRC32FileChecksum checksum = null;
  final String nnId = params.namenodeId();
  DFSClient dfsclient = newDfsClient(nnId, conf);
  try {
    checksum = dfsclient.getFileChecksum(path, Long.MAX_VALUE);
    dfsclient.close();
    dfsclient = null;
  } finally {
    IOUtils.cleanup(LOG, dfsclient);
  }
  final byte[] js = JsonUtil.toJsonString(checksum).getBytes(Charsets.UTF_8);
  DefaultFullHttpResponse resp =
    new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(js));

  resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8);
  resp.headers().set(CONTENT_LENGTH, js.length);
  resp.headers().set(CONNECTION, CLOSE);
  ctx.writeAndFlush(resp).addListener(ChannelFutureListener.CLOSE);
}
项目:hadoop    文件:TestGetBlockLocations.java   
private static FSNamesystem setupFileSystem() throws IOException {
  Configuration conf = new Configuration();
  conf.setLong(DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, 1L);
  FSEditLog editlog = mock(FSEditLog.class);
  FSImage image = mock(FSImage.class);
  when(image.getEditLog()).thenReturn(editlog);
  final FSNamesystem fsn = new FSNamesystem(conf, image, true);

  final FSDirectory fsd = fsn.getFSDirectory();
  INodesInPath iip = fsd.getINodesInPath("/", true);
  PermissionStatus perm = new PermissionStatus(
      "hdfs", "supergroup",
      FsPermission.createImmutable((short) 0x1ff));
  final INodeFile file = new INodeFile(
      MOCK_INODE_ID, FILE_NAME.getBytes(Charsets.UTF_8),
      perm, 1, 1, new BlockInfoContiguous[] {}, (short) 1,
      DFS_BLOCK_SIZE_DEFAULT);
  fsn.getFSDirectory().addINode(iip, file);
  return fsn;
}
项目:hadoop    文件:CredentialsSys.java   
@Override
public void write(XDR xdr) {
  // mStamp + mHostName.length + mHostName + mUID + mGID + mAuxGIDs.count
  mCredentialsLength = 20 + mHostName.getBytes(Charsets.UTF_8).length;
  // mAuxGIDs
  if (mAuxGIDs != null && mAuxGIDs.length > 0) {
    mCredentialsLength += mAuxGIDs.length * 4;
  }
  xdr.writeInt(mCredentialsLength);

  xdr.writeInt(mStamp);
  xdr.writeString(mHostName);
  xdr.writeInt(mUID);
  xdr.writeInt(mGID);

  if((mAuxGIDs == null) || (mAuxGIDs.length == 0)) {
    xdr.writeInt(0);
  } else {
    xdr.writeInt(mAuxGIDs.length);
    for (int i = 0; i < mAuxGIDs.length; i++) {
      xdr.writeInt(mAuxGIDs[i]);
    }
  }
}
项目:hadoop    文件:MountResponse.java   
/** Response for RPC call {@link MountInterface.MNTPROC#EXPORT} */
public static XDR writeExportList(XDR xdr, int xid, List<String> exports,
    List<NfsExports> hostMatcher) {
  assert (exports.size() == hostMatcher.size());

  RpcAcceptedReply.getAcceptInstance(xid, new VerifierNone()).write(xdr);
  for (int i = 0; i < exports.size(); i++) {
    xdr.writeBoolean(true); // Value follows - yes
    xdr.writeString(exports.get(i));

    // List host groups
    String[] hostGroups = hostMatcher.get(i).getHostGroupList();
    if (hostGroups.length > 0) {
      for (int j = 0; j < hostGroups.length; j++) {
        xdr.writeBoolean(true); // Value follows - yes
        xdr.writeVariableOpaque(hostGroups[j].getBytes(Charsets.UTF_8));
      }
    }
    xdr.writeBoolean(false); // Value follows - no more group
  }

  xdr.writeBoolean(false); // Value follows - no
  return xdr;
}
项目:hadoop    文件:FileHandle.java   
public FileHandle(String s) {
  MessageDigest digest;
  try {
    digest = MessageDigest.getInstance("MD5");
    handle = new byte[HANDLE_LEN];
  } catch (NoSuchAlgorithmException e) {
    LOG.warn("MD5 MessageDigest unavailable.");
    handle = null;
    return;
  }

  byte[] in = s.getBytes(Charsets.UTF_8);
  digest.update(in);

  byte[] digestbytes = digest.digest();
  for (int i = 0; i < 16; i++) {
    handle[i] = (byte) 0;
  }

  for (int i = 16; i < 32; i++) {
    handle[i] = digestbytes[i - 16];
  }
}
项目:hadoop    文件:LdapGroupsMapping.java   
String extractPassword(String pwFile) {
  if (pwFile.isEmpty()) {
    // If there is no password file defined, we'll assume that we should do
    // an anonymous bind
    return "";
  }

  StringBuilder password = new StringBuilder();
  try (Reader reader = new InputStreamReader(
      new FileInputStream(pwFile), Charsets.UTF_8)) {
    int c = reader.read();
    while (c > -1) {
      password.append((char)c);
      c = reader.read();
    }
    return password.toString().trim();
  } catch (IOException ioe) {
    throw new RuntimeException("Could not read password file: " + pwFile, ioe);
  }
}
项目:hadoop    文件:GraphiteSink.java   
public void connect() {
  if (isConnected()) {
    throw new MetricsException("Already connected to Graphite");
  }
  if (tooManyConnectionFailures()) {
    // return silently (there was ERROR in logs when we reached limit for the first time)
    return;
  }
  try {
    // Open a connection to Graphite server.
    socket = new Socket(serverHost, serverPort);
    writer = new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8);
  } catch (Exception e) {
    connectionFailures++;
    if (tooManyConnectionFailures()) {
      // first time when connection limit reached, report to logs
      LOG.error("Too many connection failures, would not try to connect again.");
    }
    throw new MetricsException("Error creating connection, "
        + serverHost + ":" + serverPort, e);
  }
}
项目:careconnect-reference-implementation    文件:CareConnectProfileValidationSupport.java   
private void loadStructureDefinitions(FhirContext theContext, Map<String, StructureDefinition> theCodeSystems, String theClasspath) {
  logD("CareConnect Loading structure definitions from classpath: "+ theClasspath);
  InputStream valuesetText = CareConnectProfileValidationSupport.class.getResourceAsStream(theClasspath);
  if (valuesetText != null) {
    InputStreamReader reader = new InputStreamReader(valuesetText, Charsets.UTF_8);

    Bundle bundle = theContext.newXmlParser().parseResource(Bundle.class, reader);
    for (BundleEntryComponent next : bundle.getEntry()) {
      if (next.getResource() instanceof StructureDefinition) {
        StructureDefinition nextSd = (StructureDefinition) next.getResource();
        nextSd.getText().setDivAsString("");
        String system = nextSd.getUrl();
        if (isNotBlank(system)) {
          theCodeSystems.put(system, nextSd);
        }
      }
    }
  } else {
    log.warn("Unable to load resource: {}", theClasspath);
  }
}
项目:hadoop    文件:Display.java   
@Override
public int read() throws IOException {
  int ret;
  if (null == inbuf || -1 == (ret = inbuf.read())) {
    if (!r.next(key, val)) {
      return -1;
    }
    byte[] tmp = key.toString().getBytes(Charsets.UTF_8);
    outbuf.write(tmp, 0, tmp.length);
    outbuf.write('\t');
    tmp = val.toString().getBytes(Charsets.UTF_8);
    outbuf.write(tmp, 0, tmp.length);
    outbuf.write('\n');
    inbuf.reset(outbuf.getData(), outbuf.getLength());
    outbuf.reset();
    ret = inbuf.read();
  }
  return ret;
}
项目:hadoop    文件:Display.java   
/**
 * Read a single byte from the stream.
 */
@Override
public int read() throws IOException {
  if (pos < buffer.length) {
    return buffer[pos++];
  }
  if (!fileReader.hasNext()) {
    return -1;
  }
  writer.write(fileReader.next(), encoder);
  encoder.flush();
  if (!fileReader.hasNext()) {
    // Write a new line after the last Avro record.
    output.write(System.getProperty("line.separator")
                     .getBytes(Charsets.UTF_8));
    output.flush();
  }
  pos = 0;
  buffer = output.toByteArray();
  output.reset();
  return read();
}
项目:hadoop    文件:HtmlQuoting.java   
/**
 * Quote the given item to make it html-safe.
 * @param item the string to quote
 * @return the quoted string
 */
public static String quoteHtmlChars(String item) {
  if (item == null) {
    return null;
  }
  byte[] bytes = item.getBytes(Charsets.UTF_8);
  if (needsQuoting(bytes, 0, bytes.length)) {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try {
      quoteHtmlChars(buffer, bytes, 0, bytes.length);
      return buffer.toString("UTF-8");
    } catch (IOException ioe) {
      // Won't happen, since it is a bytearrayoutputstream
      return null;
    }
  } else {
    return item;
  }
}
项目:q-mail    文件:PgpMessageBuilderTest.java   
private static void assertContentOfBodyPartEquals(String reason, BodyPart signatureBodyPart, String expected) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InputStream inputStream = MimeUtility.decodeBody(signatureBodyPart.getBody());
        IOUtils.copy(inputStream, bos);
        Assert.assertEquals(reason, expected, new String(bos.toByteArray(), Charsets.UTF_8));
    } catch (IOException | MessagingException e) {
        Assert.fail();
    }
}
项目:CustomWorldGen    文件:FMLCommonHandler.java   
/**
 * Loads a lang file, first searching for a marker to enable the 'extended' format {escape characters}
 * If the marker is not found it simply returns and let the vanilla code load things.
 * The Marker is 'PARSE_ESCAPES' by itself on a line starting with '#' as such:
 * #PARSE_ESCAPES
 *
 * @param table The Map to load each key/value pair into.
 * @param inputstream Input stream containing the lang file.
 * @return A new InputStream that vanilla uses to load normal Lang files, Null if this is a 'enhanced' file and loading is done.
 */
public InputStream loadLanguage(Map<String, String> table, InputStream inputstream) throws IOException
{
    byte[] data = IOUtils.toByteArray(inputstream);

    boolean isEnhanced = false;
    for (String line : IOUtils.readLines(new ByteArrayInputStream(data), Charsets.UTF_8))
    {
        if (!line.isEmpty() && line.charAt(0) == '#')
        {
            line = line.substring(1).trim();
            if (line.equals("PARSE_ESCAPES"))
            {
                isEnhanced = true;
                break;
            }
        }
    }

    if (!isEnhanced)
        return new ByteArrayInputStream(data);

    Properties props = new Properties();
    props.load(new InputStreamReader(new ByteArrayInputStream(data), Charsets.UTF_8));
    for (Entry<Object, Object> e : props.entrySet())
    {
        table.put((String)e.getKey(), (String)e.getValue());
    }
    props.clear();
    return null;
}
项目:fastmq    文件:BookKeeperTest.java   
@Test
    public void readEntry() throws Exception {
        BookKeeper keeper = getKeeper();
        LedgerHandle ledgerHandle = keeper.openLedger(55L, BookKeeper.DigestType.MAC, "".getBytes(Charsets.UTF_8));
//        ledgerHandle.addEntry("Hello World".getBytes());
        Enumeration<LedgerEntry> enumeration = ledgerHandle.readEntries(1, 99);
        while (enumeration.hasMoreElements()) {
            LedgerEntry ledgerEntry = enumeration.nextElement();
            System.out.println(ledgerEntry.getEntryId());
        }
    }
项目:rest-client    文件:RestClientTest.java   
@Test
public void formData_contentType() throws Exception {
    HttpResponse<JsonNode> response = client.post(BASE_URL + "/echoMultipart")
            .field("name", "Mark")
            .asJson();

    JSONArray contentTypeValues = response.getBody().getObject().getJSONObject("headers").getJSONArray(HttpHeaders.CONTENT_TYPE);
    assertEquals(1, contentTypeValues.length());
    assertEquals(ContentType.APPLICATION_FORM_URLENCODED.withCharset(Charsets.UTF_8).toString(), contentTypeValues.getString(0));
}
项目:personium-core    文件:DavMetadataFile.java   
/**
 * save to the file.
 */
public void save() {
    this.incrementVersion();
    String jsonStr = JSONObject.toJSONString(this.getJSON());
    try {
        Files.write(this.file.toPath(), jsonStr.getBytes(Charsets.UTF_8));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:hadoop-oss    文件:StreamPumper.java   
protected void pump() throws IOException {
  InputStreamReader inputStreamReader = new InputStreamReader(
      stream, Charsets.UTF_8);
  BufferedReader br = new BufferedReader(inputStreamReader);
  String line = null;
  while ((line = br.readLine()) != null) {
    if (type == StreamType.STDOUT) {
      log.info(logPrefix + ": " + line);
    } else {
      log.warn(logPrefix + ": " + line);          
    }
  }
}
项目:hadoop-oss    文件:GangliaContext.java   
/**
 * Puts a string into the buffer by first writing the size of the string
 * as an int, followed by the bytes of the string, padded if necessary to
 * a multiple of 4.
 */
protected void xdr_string(String s) {
  byte[] bytes = s.getBytes(Charsets.UTF_8);
  int len = bytes.length;
  xdr_int(len);
  System.arraycopy(bytes, 0, buffer, offset, len);
  offset += len;
  pad();
}
项目:Backmemed    文件:LanguageMap.java   
public LanguageMap()
{
    try
    {
        InputStream inputstream = LanguageMap.class.getResourceAsStream("/assets/minecraft/lang/en_us.lang");

        for (String s : IOUtils.readLines(inputstream, Charsets.UTF_8))
        {
            if (!s.isEmpty() && s.charAt(0) != 35)
            {
                String[] astring = (String[])Iterables.toArray(EQUAL_SIGN_SPLITTER.split(s), String.class);

                if (astring != null && astring.length == 2)
                {
                    String s1 = astring[0];
                    String s2 = NUMERIC_VARIABLE_PATTERN.matcher(astring[1]).replaceAll("%$1s");
                    this.languageList.put(s1, s2);
                }
            }
        }

        this.lastUpdateTimeInMilliseconds = System.currentTimeMillis();
    }
    catch (IOException var7)
    {
        ;
    }
}
项目:hadoop-oss    文件:AbstractGangliaSink.java   
/**
 * Puts a string into the buffer by first writing the size of the string as an
 * int, followed by the bytes of the string, padded if necessary to a multiple
 * of 4.
 * @param s the string to be written to buffer at offset location
 */
protected void xdr_string(String s) {
  byte[] bytes = s.getBytes(Charsets.UTF_8);
  int len = bytes.length;
  xdr_int(len);
  System.arraycopy(bytes, 0, buffer, offset, len);
  offset += len;
  pad();
}
项目:hadoop    文件:FileBasedIPList.java   
/**
 * Reads the lines in a file.
 * @param fileName
 * @return lines in a String array; null if the file does not exist or if the
 * file name is null
 * @throws IOException
 */
private static String[] readLines(String fileName) throws IOException {
  try {
    if (fileName != null) {
      File file = new File (fileName);
      if (file.exists()) {
        try (
            Reader fileReader = new InputStreamReader(
                new FileInputStream(file), Charsets.UTF_8);
            BufferedReader bufferedReader = new BufferedReader(fileReader)) {
          List<String> lines = new ArrayList<String>();
          String line = null;
          while ((line = bufferedReader.readLine()) != null) {
            lines.add(line);
          }
          if (LOG.isDebugEnabled()) {
            LOG.debug("Loaded IP list of size = " + lines.size() +
                " from file = " + fileName);
          }
          return (lines.toArray(new String[lines.size()]));
        }
      } else {
        LOG.debug("Missing ip list file : "+ fileName);
      }
    }
  } catch (IOException ioe) {
    LOG.error(ioe);
    throw ioe;
  }
  return null;
}
项目:hadoop    文件:BZip2Codec.java   
private void writeStreamHeader() throws IOException {
  if (super.out != null) {
    // The compressed bzip2 stream should start with the
    // identifying characters BZ. Caller of CBZip2OutputStream
    // i.e. this class must write these characters.
    out.write(HEADER.getBytes(Charsets.UTF_8));
  }
}
项目:hadoop-oss    文件:KeyProvider.java   
/**
 * Serialize the metadata to a set of bytes.
 * @return the serialized bytes
 * @throws IOException
 */
protected byte[] serialize() throws IOException {
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  JsonWriter writer = new JsonWriter(
      new OutputStreamWriter(buffer, Charsets.UTF_8));
  try {
    writer.beginObject();
    if (cipher != null) {
      writer.name(CIPHER_FIELD).value(cipher);
    }
    if (bitLength != 0) {
      writer.name(BIT_LENGTH_FIELD).value(bitLength);
    }
    if (created != null) {
      writer.name(CREATED_FIELD).value(created.getTime());
    }
    if (description != null) {
      writer.name(DESCRIPTION_FIELD).value(description);
    }
    if (attributes != null && attributes.size() > 0) {
      writer.name(ATTRIBUTES_FIELD).beginObject();
      for (Map.Entry<String, String> attribute : attributes.entrySet()) {
        writer.name(attribute.getKey()).value(attribute.getValue());
      }
      writer.endObject();
    }
    writer.name(VERSIONS_FIELD).value(versions);
    writer.endObject();
    writer.flush();
  } finally {
    writer.close();
  }
  return buffer.toByteArray();
}