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


Java Charsets類代碼示例

本文整理匯總了Java中org.apache.commons.io.Charsets的典型用法代碼示例。如果您正苦於以下問題:Java Charsets類的具體用法?Java Charsets怎麽用?Java Charsets使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: loadLocaleData

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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);
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:18,代碼來源:Locale.java

示例2: setUpDirectories

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:22,代碼來源:AbstractLifecycle.java

示例3: loadLocaleData

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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);
            }
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:20,代碼來源:Locale.java

示例4: loadLocaleData

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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);
            }
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:18,代碼來源:Locale.java

示例5: loadLocaleData

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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);
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:18,代碼來源:Lang.java

示例6: LanguageMap

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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)
    {
        ;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:29,代碼來源:LanguageMap.java

示例7: read

import org.apache.commons.io.Charsets; //導入依賴的package包/類
@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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:20,代碼來源:Display.java

示例8: quoteHtmlChars

import org.apache.commons.io.Charsets; //導入依賴的package包/類
/**
 * 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;
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:24,代碼來源:HtmlQuoting.java

示例9: loadStructureDefinitions

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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);
  }
}
 
開發者ID:nhsconnect,項目名稱:careconnect-reference-implementation,代碼行數:22,代碼來源:SNOMEDUKMockValidationSupport.java

示例10: checkMetrics

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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());
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:22,代碼來源:TestGangliaMetrics.java

示例11: toMap

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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;
}
 
開發者ID:chncwang,項目名稱:laozhongyi,代碼行數:17,代碼來源:HyperParameterConfig.java

示例12: read

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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;
}
 
開發者ID:chncwang,項目名稱:laozhongyi,代碼行數:21,代碼來源:HyperParameterScopeConfigReader.java

示例13: storeRecentOpened

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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);
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:18,代碼來源:QuickSearchPanel.java

示例14: loadGraphFeatures

import org.apache.commons.io.Charsets; //導入依賴的package包/類
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;
}
 
開發者ID:UKPLab,項目名稱:ijcnlp2017-cmaps,代碼行數:21,代碼來源:FeatureExtractor.java

示例15: createAncestorDirectories

import org.apache.commons.io.Charsets; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:FSDirMkdirOp.java


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