本文整理汇总了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);
}
}
}
}
示例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();
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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)
{
;
}
}
示例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;
}
示例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;
}
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}