本文整理匯總了Java中java.io.UnsupportedEncodingException類的典型用法代碼示例。如果您正苦於以下問題:Java UnsupportedEncodingException類的具體用法?Java UnsupportedEncodingException怎麽用?Java UnsupportedEncodingException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UnsupportedEncodingException類屬於java.io包,在下文中一共展示了UnsupportedEncodingException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hashinate
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
/**
* Given an Object value, pick a partition to store the data. Currently only String objects can be hashed.
*
* @param value The value to hash.
* @param partitionCount The number of partitions to choose from.
* @return A value between 0 and partitionCount-1, hopefully pretty evenly
* distributed.
*/
static int hashinate(Object value, int partitionCount) {
if (value instanceof String) {
String string = (String) value;
try {
byte bytes[] = string.getBytes("UTF-8");
int hashCode = 0;
int offset = 0;
for (int ii = 0; ii < bytes.length; ii++) {
hashCode = 31 * hashCode + bytes[offset++];
}
return java.lang.Math.abs(hashCode % partitionCount);
} catch (UnsupportedEncodingException e) {
hostLogger.l7dlog( Level.FATAL, LogKeys.host_TheHashinator_ExceptionHashingString.name(), new Object[] { string }, e);
HStore.crashDB();
}
}
hostLogger.l7dlog(Level.FATAL, LogKeys.host_TheHashinator_AttemptedToHashinateNonLongOrString.name(), new Object[] { value
.getClass().getName() }, null);
HStore.crashDB();
return -1;
}
示例2: setConfigurationXML64
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
/**
* Sets the configuration in XML in a Base64 decode form.
* @param configurationXML64 the new configuration xm l64
*/
public void setConfigurationXML64(String[] configurationXML64) {
String[] configXML = new String[configurationXML64.length];
for (int i = 0; i < configurationXML64.length; i++) {
try {
if (configurationXML64[i]==null || configurationXML64[i].equals("")) {
configXML[i] = null;
} else {
configXML[i] = new String(Base64.decodeBase64(configurationXML64[i].getBytes()), "UTF8");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
this.getDynForm().setOntoArgsXML(configXML);
this.getDynTableJPanel().refreshTableModel();
if (this.getSelectedIndex()==1) {
this.setXMLText();
}
}
示例3: stringToMD5
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
public static String stringToMD5(String string) {
try {
byte[] hash = MessageDigest.getInstance(Coder.KEY_MD5).digest(string.getBytes("UTF-8"));
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 255) < 16) {
hex.append("0");
}
hex.append(Integer.toHexString(b & 255));
}
return hex.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
} catch (UnsupportedEncodingException e2) {
e2.printStackTrace();
return null;
}
}
示例4: getLabelFromBuiltIn
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
private String getLabelFromBuiltIn(String uri){
try {
IRI iri = IRI.create(URLDecoder.decode(uri, "UTF-8"));
// if IRI is built-in entity
if(iri.isReservedVocabulary()) {
// use the short form
String label = sfp.getShortForm(iri);
// if it is a XSD numeric data type, we attach "value"
if(uri.equals(XSD.nonNegativeInteger.getURI()) || uri.equals(XSD.integer.getURI())
|| uri.equals(XSD.negativeInteger.getURI()) || uri.equals(XSD.decimal.getURI())
|| uri.equals(XSD.xdouble.getURI()) || uri.equals(XSD.xfloat.getURI())
|| uri.equals(XSD.xint.getURI()) || uri.equals(XSD.xshort.getURI())
|| uri.equals(XSD.xbyte.getURI()) || uri.equals(XSD.xlong.getURI())
){
label += " value";
}
return label;
}
} catch (UnsupportedEncodingException e) {
logger.error("Getting short form of " + uri + "failed.", e);
}
return null;
}
示例5: sendChannelMsg
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
private void sendChannelMsg(String msgStr) {
RtcEngine rtcEngine = rtcEngine();
if (mDataStreamId <= 0) {
mDataStreamId = rtcEngine.createDataStream(true, true); // boolean reliable, boolean ordered
}
if (mDataStreamId < 0) {
String errorMsg = "Create data stream error happened " + mDataStreamId;
log.warn(errorMsg);
showLongToast(errorMsg);
return;
}
byte[] encodedMsg;
try {
encodedMsg = msgStr.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
encodedMsg = msgStr.getBytes();
}
rtcEngine.sendStreamMessage(mDataStreamId, encodedMsg);
}
示例6: getRequestData
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
/**
* 打包請求數據
*
* @param type
* @param paramPath
* @return
*/
private static byte[] getRequestData(bussinessType type, String paramPath) {
Map<String, String> dbInfo = getDBInfo(type);
UAVHttpMessage request = new UAVHttpMessage();
String dataStr = getFileData(paramPath);
request.putRequest(DataStoreProtocol.MONGO_REQUEST_DATA, dataStr);
request.putRequest(DataStoreProtocol.DATASTORE_NAME, dbInfo.get(k_dataStoreName));
request.putRequest(DataStoreProtocol.MONGO_COLLECTION_NAME, dbInfo.get(k_conllectionName));
String jsonStr = JSONHelper.toString(request);
byte[] datab = null;
try {
datab = jsonStr.getBytes("utf-8");
}
catch (UnsupportedEncodingException e) {
LOG.info("HttpTestApphub getRequestData \n" + e.getMessage());
}
return datab;
}
示例7: sha256
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
public static String sha256(String base) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(base.getBytes("UTF-8"));
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < hash.length; i++) {
String hex = Integer.toHexString(0xff & hash[i]);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
} catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
示例8: parseText
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
/**
* Parse Text Frames.
*
* @param bframes
* @param offset
* @param size
* @param skip
* @return
*/
protected String parseText(byte[] bframes, int offset, int size, int skip)
{
String value = null;
try
{
String enc = ENC_TYPES[0];
if ( bframes[offset] >= 0 && bframes[offset] < 4 )
{
enc = ENC_TYPES[bframes[offset]];
}
value = new String(bframes, offset + skip, size - skip, enc);
value = chopSubstring(value, 0, value.length());
}
catch (UnsupportedEncodingException e)
{
system.error("ID3v2 Encoding error: " + e.getMessage());
}
return value;
}
示例9: convert
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
public ByteBuffer convert(Tag tag) throws UnsupportedEncodingException {
ByteBuffer ogg = creator.convert(tag);
int tagLength = ogg.capacity() + VorbisHeader.FIELD_PACKET_TYPE_LENGTH + VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH + OggVorbisCommentTagCreator.FIELD_FRAMING_BIT_LENGTH;
ByteBuffer buf = ByteBuffer.allocate(tagLength);
//[packet type=comment0x03]['vorbis']
buf.put((byte) VorbisPacketType.COMMENT_HEADER.getType());
buf.put(VorbisHeader.CAPTURE_PATTERN_AS_BYTES);
//The actual tag
buf.put(ogg);
//Framing bit = 1
buf.put(FRAMING_BIT_VALID_VALUE);
buf.rewind();
return buf;
}
示例10: aesEncode
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
/**
* 可逆加密
* @param secret
* @param key
* @return
*/
public static String aesEncode(String secret,String key){
if (StringUtils.isEmpty(secret) || StringUtils.isEmpty(key)){
return null;
}
byte[] retByte = new byte[0];
try {
retByte = AESEncode(secret.getBytes(chart_set_utf8),key);
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage(),e);
}
if (retByte != null) {
return bytesToHexString(retByte);
}
return null;
}
示例11: toTriple
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
/**
* This method converts a string (in n-triples format) into a Jena triple
*
* @param string containing single n-triples triple
* @return Triple
*/
public static Triple toTriple(final String string) {
// Create Jena model
Model inputModel = createDefaultModel();
try {
// Load model with arg string (expecting n-triples)
inputModel = inputModel.read(new StringInputStream(string), null, strLangNTriples);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
// Since there is only one statement, get it
final Statement stmt = inputModel.listStatements().nextStatement();
// Return the Jena triple which the statement represents
return stmt.asTriple();
}
示例12: writeLenString
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
final void writeLenString(String s, String encoding, String serverEncoding, SingleByteCharsetConverter converter, boolean parserKnowsUnicode,
MySQLConnection conn) throws UnsupportedEncodingException, SQLException {
byte[] b = null;
if (converter != null) {
b = converter.toBytes(s);
} else {
b = StringUtils.getBytes(s, encoding, serverEncoding, parserKnowsUnicode, conn, conn.getExceptionInterceptor());
}
int len = b.length;
ensureCapacity(len + 9);
writeFieldLength(len);
System.arraycopy(b, 0, this.byteBuffer, this.position, len);
this.position += len;
}
示例13: main
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
public static void main(String[] args) throws GeneralSecurityException, UnsupportedEncodingException {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
KeyPair kp = kpg.genKeyPair();
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(),
RSAPublicKeySpec.class);
RSAPrivateKeySpec priv = fact.getKeySpec(kp.getPrivate(),
RSAPrivateKeySpec.class);
publicKey = fact.generatePublic(pub);
privateKey = fact.generatePrivate(priv);
String foo = rsaEncrypt("foo");
byte[] decode = Base64.getDecoder().decode("foo");
System.out.println(Base64.getEncoder().encodeToString(decode));
System.out.println(rsaDecrypt(foo));
}
示例14: getSHA512
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
private String getSHA512(String passwordToHash) {
String generatedPassword = null;
try {
String salt = getKeyProvider().getKey(null);
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(salt.getBytes("UTF-8"));
byte[] bytes = md.digest(passwordToHash.getBytes("UTF-8"));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
}
generatedPassword = sb.toString();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
}
return generatedPassword;
}
示例15: getEligibleJobs
import java.io.UnsupportedEncodingException; //導入依賴的package包/類
public List<Job> getEligibleJobs(boolean male, int maxLength) {
if(maxLength < 1)
throw new IllegalArgumentException("Violation of precondidition: " +
"getEligibleJobs. maxLength must be greater than 0.");
List<Job> eligible = new ArrayList<>();
List<Job> pool;
if(male)
pool = getMaleBaseClasses();
else
pool = getFemaleBaseClasses();
try {
for(Job j : pool) {
if(j.getJid().getBytes("shift-jis").length <= maxLength && j.getItemType()
!= ItemType.Staves && j.getItemType() != ItemType.Beaststone)
eligible.add(j);
}
} catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
return eligible;
}