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


Java Charsets類代碼示例

本文整理匯總了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();
	}
}
 
開發者ID:abuchanan920,項目名稱:historybook-import,代碼行數:21,代碼來源:Indexer.java

示例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);
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:23,代碼來源:DownloadedTextures.java

示例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();
}
 
開發者ID:IIDP,項目名稱:OSTMap,代碼行數:17,代碼來源:KeyExtractionTest.java

示例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;
}
 
開發者ID:waterguo,項目名稱:antsdb,代碼行數:20,代碼來源:MysqlSlave.java

示例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);
}
 
開發者ID:Notronix,項目名稱:NewRelicEvents,代碼行數:24,代碼來源:NewRelicEvent.java

示例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;
}
 
開發者ID:europeana,項目名稱:search,代碼行數:21,代碼來源:TestLazyCores.java

示例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());
  }
 
開發者ID:europeana,項目名稱:search,代碼行數:19,代碼來源:TestLazyCores.java

示例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();
}
 
開發者ID:bduisenov,項目名稱:decompile-and-attach,代碼行數:22,代碼來源:DecompileAndAttachAction.java

示例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}"));
		}
	}
 
開發者ID:raghavendar-ts,項目名稱:Elasticsearch-Report-Plugin,代碼行數:18,代碼來源:ESReportPluginRestHandler.java

示例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();
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:26,代碼來源:HttpClientSourceIT.java

示例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());
    }
}
 
開發者ID:DukeMobileTech,項目名稱:AndroidSurvey,代碼行數:19,代碼來源:ListOfItemsQuestionFragment.java

示例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;
}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:24,代碼來源:BaseWorkerContext.java

示例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.
    }
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-commons-codec,代碼行數:26,代碼來源:QuotedPrintableCodecTest.java

示例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.
    }
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-commons-codec,代碼行數:26,代碼來源:QuotedPrintableCodecTest.java

示例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);
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-commons-codec,代碼行數:27,代碼來源:URLCodecTest.java


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