本文整理匯總了Java中org.apache.commons.codec.Charsets類的典型用法代碼示例。如果您正苦於以下問題:Java Charsets類的具體用法?Java Charsets怎麽用?Java Charsets使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Charsets類屬於org.apache.commons.codec包,在下文中一共展示了Charsets類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: index
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
/**
* Uploads the given HistoryRecord to the search index service
*
* @param record HistoryRecord to send to index. Should have a body.
*/
public void index(HistoryRecord record) {
try {
if (record.getBody() != null) {
String url = baseUrl + "/collections/"
+ collection + "/"
+ URLEncoder.encode(record.getUrl(), Charsets.UTF_8.name());
if (record.getTimestamp() != null) {
url = url + "/" + URLEncoder.encode(record.getTimestamp(), Charsets.UTF_8.name());
}
Request.Post(url).bodyString(record.getBody(), ContentType.TEXT_HTML).execute();
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: PlayerSkin
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
public PlayerSkin(UUID uuid){
profile = new GameProfile(uuid, ProfileUtil.getUsername(uuid));
PropertyMap properties = ProfileUtil.getProperties(uuid);
if(properties !=null){
Property textureProperty = Iterables.getFirst(properties.get("textures"), null);
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = null;
MinecraftTexturesPayload result;
try {
String json = new String(Base64.decodeBase64(textureProperty.getValue()), Charsets.UTF_8);
result = gson.fromJson(json, MinecraftTexturesPayload.class);
map = result.getTextures();
} catch (JsonParseException e) {
ModLogger.error("Could not decode textures payload", e);
map = new HashMap<MinecraftProfileTexture.Type, MinecraftProfileTexture>();
}
for(Type type : map.keySet()){
Minecraft.getMinecraft().getSkinManager().loadSkin(map.get(type), type, this);
}
}
//playerTextures = downloadPlayerTextures(profile);
}
示例3: calcData
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
@BeforeClass
public static void calcData() throws AccumuloException, AccumuloSecurityException, InterruptedException, IOException {
ZonedDateTime time = ZonedDateTime.parse("Fri Apr 29 09:05:55 +0000 2016", formatterExtract);
ts = time.toEpochSecond();
tweet = "{\"created_at\":\"Fri Apr 29 09:05:55 +0000 2016\",\"id\":725974381906804738,\"id_str\":\"725974381906804738\",\"text\":\"Das sage ich dir gleich, das funktioniert doch nie! #haselnuss\",\"user\":{\"id\":179905182,\"name\":\"Peter Tosh\",\"screen_name\":\"PeTo\"}}";
int bufferSize = tweet.length();
ByteBuffer bb1 = ByteBuffer.allocate(bufferSize);
bb1.put(tweet.getBytes(Charsets.UTF_8));
hash = hashFunction.hashBytes(bb1.array()).asInt();
ByteBuffer bb2 = ByteBuffer.allocate(Long.BYTES + Integer.BYTES);
bb2.putLong(ts).putInt(hash);
bytes = bb2.array();
}
示例4: toParameter
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
private Object toParameter(Column col) {
Object value;
if (col instanceof StringColumn){
// use UTF-8 to match open replicator default charset
value = new String((byte[])col.getValue(), Charsets.UTF_8);
} else {
value = col.getValue();
}
if (!(value instanceof java.util.Date)) {
return value;
}
if (value instanceof java.sql.Date || value instanceof java.sql.Timestamp) {
return value;
}
// open replicator sometimes use java.util.Date instead of java.sql.Date.
value = new Timestamp(((java.util.Date)value).getTime());
return value;
}
示例5: addAttribute
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
/**
* Adds a textual attribute to the custom event. There is a limit of 254 total attributes per event.
*
* @param name the name of the attribute
* @param value the value of the attribute (maximum length of 4kb)
* @throws APIViolationException if there are too many attributes or if the attribute length is exceeded.
*/
public void addAttribute(String name, String value) throws APIViolationException
{
if (tooManyAttributes())
{
throw new APIViolationException("Attribute limit exceeded.");
}
String attributeValue = trim(value);
if (attributeValue != null && attributeValue.getBytes(Charsets.UTF_8).length >= 4000)
{
throw new APIViolationException("Attribute is over the 4kb limit.");
}
attributes.put(cleanAttributeName(name), attributeValue);
}
示例6: init
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
private CoreContainer init() throws Exception {
solrHomeDirectory = createTempDir();
for (int idx = 1; idx < 10; ++idx) {
copyMinConf(new File(solrHomeDirectory, "collection" + idx));
}
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
File solrXml = new File(solrHomeDirectory, "solr.xml");
FileUtils.write(solrXml, LOTS_SOLR_XML, Charsets.UTF_8.toString());
ConfigSolrXmlOld config = (ConfigSolrXmlOld) ConfigSolr.fromFile(loader, solrXml);
CoresLocator locator = new SolrXMLCoresLocator.NonPersistingLocator(LOTS_SOLR_XML, config);
final CoreContainer cores = new CoreContainer(loader, config, locator);
cores.load();
return cores;
}
示例7: writeCustomConfig
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
private void writeCustomConfig(String coreName, String config, String schema, String rand_snip) throws IOException {
File coreRoot = new File(solrHomeDirectory, coreName);
File subHome = new File(coreRoot, "conf");
if (!coreRoot.exists()) {
assertTrue("Failed to make subdirectory ", coreRoot.mkdirs());
}
// Write the file for core discovery
FileUtils.writeStringToFile(new File(coreRoot, "core.properties"), "name=" + coreName +
System.getProperty("line.separator") + "transient=true" +
System.getProperty("line.separator") + "loadOnStartup=true", Charsets.UTF_8.toString());
FileUtils.writeStringToFile(new File(subHome, "solrconfig.snippet.randomindexconfig.xml"), rand_snip, Charsets.UTF_8.toString());
FileUtils.writeStringToFile(new File(subHome, "solrconfig.xml"), config, Charsets.UTF_8.toString());
FileUtils.writeStringToFile(new File(subHome, "schema.xml"), schema, Charsets.UTF_8.toString());
}
示例8: addFileEntry
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
private static void addFileEntry(ZipOutputStream jarOS, String relativePath, Set<String> writtenPaths,
CharSequence decompiled) throws IOException {
if (!writtenPaths.add(relativePath))
return;
ByteArrayInputStream fileIS = new ByteArrayInputStream(decompiled.toString().getBytes(Charsets.toCharset("UTF-8")));
long size = decompiled.length();
ZipEntry e = new ZipEntry(relativePath);
if (size == 0) {
e.setMethod(ZipEntry.STORED);
e.setSize(0);
e.setCrc(0);
}
jarOS.putNextEntry(e);
try {
FileUtil.copy(fileIS, jarOS);
} finally {
fileIS.close();
}
jarOS.closeEntry();
}
示例9: handleRequest
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
public void handleRequest(final RestRequest request, final RestChannel channel) {
String inputStr = new String(request.content().toBytes(), Charsets.UTF_8);
JSONObject input = null;
if (!request.method().equals(GET)) {
input = new JSONObject(inputStr);
}
System.out.println("Path:" + request.path());
if (request.path().equals("/_river/report/now")) {
ESReport esReport = new ESReport(client);
esReport.process(inputStr);
channel.sendResponse(new BytesRestResponse(OK, "{status:finished}"));
}
}
示例10: post
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
@POST
public Response post(
@Context HttpHeaders h,
@FormParam(OAuth2ConfigBean.GRANT_TYPE_KEY) String type
) {
String[] creds = new String(
Base64.decodeBase64(h.getHeaderString(HttpHeaders.AUTHORIZATION).substring("Basic ".length())), Charsets.UTF_8)
.split(":");
if (creds.length == 2 && creds[0].equals(CLIENT_ID) && creds[1].equals(CLIENT_SECRET)) {
token = RandomStringUtils.randomAlphanumeric(16);
String tokenResponse = "{\n" +
" \"token_type\": \"Bearer\",\n" +
" \"expires_in\": \"3600\",\n" +
" \"ext_expires_in\": \"0\",\n" +
" \"expires_on\": \"1484788319\",\n" +
" \"not_before\": \"1484784419\",\n" +
" \"access_token\": \"" + token + "\"\n" +
"}";
tokenGetCount++;
return Response.ok().entity(tokenResponse).build();
}
return Response.status(Response.Status.FORBIDDEN).build();
}
示例11: deserialize
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
@SuppressLint("LongLogTag")
@Override
protected void deserialize(String responseText) {
if (responseText.equals("")) return;
InputStream input = new ByteArrayInputStream(responseText.getBytes(Charsets.UTF_8));
InputStreamReader inputReader = new InputStreamReader(input);
CSVReader reader = new CSVReader(inputReader);
String[] listOfResponses;
try {
listOfResponses = reader.readNext();
for (int i = 0; i < listOfResponses.length; i++) {
if (mResponses.size() > i)
mResponses.get(i).setText(listOfResponses[i]);
}
} catch (IOException e) {
if(BuildConfig.DEBUG) Log.e(TAG, "IOException " + e.getMessage());
}
}
示例12: determineCacheId
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
private String determineCacheId(ValueSet vs, boolean heirarchical) throws Exception {
// just the content logical definition is hashed
ValueSet vsid = new ValueSet();
vsid.setCompose(vs.getCompose());
JsonParser parser = new JsonParser();
parser.setOutputStyle(OutputStyle.NORMAL);
ByteArrayOutputStream b = new ByteArrayOutputStream();
parser.compose(b, vsid);
b.close();
String s = new String(b.toByteArray(), Charsets.UTF_8);
// any code systems we can find, we add these too.
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
CodeSystem cs = fetchCodeSystem(inc.getSystem());
if (cs != null) {
String css = cacheValue(cs);
s = s + css;
}
}
s = s + "-"+Boolean.toString(heirarchical);
String r = Integer.toString(s.hashCode());
// TextFile.stringToFile(s, Utilities.path(cache, r+".id.json"));
return r;
}
示例13: testEncodeObjects
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
@Test
public void testEncodeObjects() throws Exception {
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String plain = "1+1 = 2";
String encoded = (String) qpcodec.encode((Object) plain);
assertEquals("Basic quoted-printable encoding test",
"1+1 =3D 2", encoded);
final byte[] plainBA = plain.getBytes(Charsets.UTF_8);
final byte[] encodedBA = (byte[]) qpcodec.encode((Object) plainBA);
encoded = new String(encodedBA);
assertEquals("Basic quoted-printable encoding test",
"1+1 =3D 2", encoded);
final Object result = qpcodec.encode((Object) null);
assertEquals( "Encoding a null Object should return null", null, result);
try {
final Object dObj = new Double(3.0);
qpcodec.encode( dObj );
fail( "Trying to url encode a Double object should cause an exception.");
} catch (final EncoderException ee) {
// Exception expected, test segment passes.
}
}
示例14: testDecodeObjects
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
@Test
public void testDecodeObjects() throws Exception {
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String plain = "1+1 =3D 2";
String decoded = (String) qpcodec.decode((Object) plain);
assertEquals("Basic quoted-printable decoding test",
"1+1 = 2", decoded);
final byte[] plainBA = plain.getBytes(Charsets.UTF_8);
final byte[] decodedBA = (byte[]) qpcodec.decode((Object) plainBA);
decoded = new String(decodedBA);
assertEquals("Basic quoted-printable decoding test",
"1+1 = 2", decoded);
final Object result = qpcodec.decode((Object) null);
assertEquals( "Decoding a null Object should return null", null, result);
try {
final Object dObj = new Double(3.0);
qpcodec.decode( dObj );
fail( "Trying to url encode a Double object should cause an exception.");
} catch (final DecoderException ee) {
// Exception expected, test segment passes.
}
}
示例15: testEncodeObjects
import org.apache.commons.codec.Charsets; //導入依賴的package包/類
@Test
public void testEncodeObjects() throws Exception {
final URLCodec urlCodec = new URLCodec();
final String plain = "Hello there!";
String encoded = (String) urlCodec.encode((Object) plain);
assertEquals("Basic URL encoding test",
"Hello+there%21", encoded);
final byte[] plainBA = plain.getBytes(Charsets.UTF_8);
final byte[] encodedBA = (byte[]) urlCodec.encode((Object) plainBA);
encoded = new String(encodedBA);
assertEquals("Basic URL encoding test",
"Hello+there%21", encoded);
final Object result = urlCodec.encode((Object) null);
assertEquals( "Encoding a null Object should return null", null, result);
try {
final Object dObj = new Double(3.0);
urlCodec.encode( dObj );
fail( "Trying to url encode a Double object should cause an exception.");
} catch (final EncoderException ee) {
// Exception expected, test segment passes.
}
this.validateState(urlCodec);
}