本文整理匯總了Java中org.apache.commons.codec.DecoderException類的典型用法代碼示例。如果您正苦於以下問題:Java DecoderException類的具體用法?Java DecoderException怎麽用?Java DecoderException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DecoderException類屬於org.apache.commons.codec包,在下文中一共展示了DecoderException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decodeHash
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
public byte[] decodeHash(String encodedHash)
{
if (!getEncodeHashAsBase64())
{
try
{
return Hex.decodeHex(encodedHash.toCharArray());
}
catch (DecoderException e)
{
throw new RuntimeException("Unable to decode password hash");
}
}
else
{
return Base64.decodeBase64(encodedHash.getBytes());
}
}
示例2: testEncryptionHelper
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
@Test
public void testEncryptionHelper() throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException,
IllegalBlockSizeException, UnsupportedEncodingException, InvalidAlgorithmParameterException, DecoderException {
// https://golang.org/src/crypto/cipher/gcm_test.go
String[][] testCases = new String[][]{
new String[]{"11754cd72aec309bf52f7687212e8957", "3c819d9a9bed087615030b65", "", "250327c674aaf477aef2675748cf6971"},
new String[]{"ca47248ac0b6f8372a97ac43508308ed", "ffd2b598feabc9019262d2be", "", "60d20404af527d248d893ae495707d1a"},
new String[]{"7fddb57453c241d03efbed3ac44e371c", "ee283a3fc75575e33efd4887", "d5de42b461646c255c87bd2962d3b9a2", "2ccda4a5415cb91e135c2a0f78c9b2fdb36d1df9b9d5e596f83e8b7f52971cb3"},
new String[]{"ab72c77b97cb5fe9a382d9fe81ffdbed", "54cc7dc2c37ec006bcc6d1da", "007c5e5b3e59df24a7c355584fc1518d", "0e1bde206a07a9c2c1b65300f8c649972b4401346697138c7a4891ee59867d0c"},
new String[]{"feffe9928665731c6d6a8f9467308308", "cafebabefacedbaddecaf888", "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
"42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091473f59854d5c2af327cd64a62cf35abd2ba6fab4"},
};
for (String[] testCase : testCases) {
SecretKeySpec k = new SecretKeySpec(new Hex().decode(testCase[0].getBytes()), "AES");
IvParameterSpec iv = new IvParameterSpec(new Hex().decode(testCase[1].getBytes()));
byte[] cipherTExt = EncryptionHelper.encrypt(k, iv, new Hex().decode(testCase[2].getBytes()));
String cipher = new String(new Hex().encode(cipherTExt));
assertEquals(cipher, testCase[3]);
assertEquals(testCase[2], new String(new Hex().encode(EncryptionHelper.decrypt(k, iv, cipherTExt))));
}
}
示例3: decodeQuotedPrintable
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
/***
* Decodes an array quoted-printable characters into an array of original bytes. Escaped characters are converted
* back to their original representation.
*
* <p>
* This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in
* RFC 1521.
* </p>
*
* @param bytes
* array of quoted-printable characters
* @return array of original bytes
* @throws DecoderException
* Thrown if quoted-printable decoding is unsuccessful
*/
public static final byte[] decodeQuotedPrintable(byte[] bytes) throws DecoderException {
if (bytes == null) {
return null;
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i = 0; i < bytes.length; i++) {
int b = bytes[i];
if (b == ESCAPE_CHAR) {
try {
int u = Character.digit((char) bytes[++i], 16);
int l = Character.digit((char) bytes[++i], 16);
if (u == -1 || l == -1) {
throw new DecoderException("Invalid quoted-printable encoding");
}
buffer.write((char) ((u << 4) + l));
} catch (ArrayIndexOutOfBoundsException e) {
throw new DecoderException("Invalid quoted-printable encoding");
}
} else {
buffer.write(b);
}
}
return buffer.toByteArray();
}
示例4: decodeUrl
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
/**
* Decodes an array of URL safe 7-bit characters into an array of original bytes. Escaped characters are converted
* back to their original representation.
*
* @param bytes
* array of URL safe characters
* @return array of original bytes
* @throws DecoderException
* Thrown if URL decoding is unsuccessful
*/
public static final byte[] decodeUrl(final byte[] bytes) throws DecoderException {
if (bytes == null) {
return null;
}
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i = 0; i < bytes.length; i++) {
final int b = bytes[i];
if (b == '+') {
buffer.write(' ');
} else if (b == ESCAPE_CHAR) {
try {
final int u = Utils.digit16(bytes[++i]);
final int l = Utils.digit16(bytes[++i]);
buffer.write((char) ((u << 4) + l));
} catch (final ArrayIndexOutOfBoundsException e) {
throw new DecoderException("Invalid URL encoding: ", e);
}
} else {
buffer.write(b);
}
}
return buffer.toByteArray();
}
示例5: decodeHex
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
/**
* Hex解碼.
*/
public static byte[] decodeHex(String input) {
try {
return Hex.decodeHex(input.toCharArray());
} catch (DecoderException e) {
throw Exceptions.unchecked(e);
}
}
示例6: unhex
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
public Encoder unhex() {
try {
data = new Hex().decode(data);
return this;
} catch (DecoderException e) {
throw new BaseException(e, "Failed to convert data from hex: %s", e.getMessage());
}
}
示例7: process
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
@Override
public String process(int lineNumber, String result) throws DeserializeException {
while (result.contains("\\X2\\")) {
int index = result.indexOf("\\X2\\");
int indexOfEnd = result.indexOf("\\X0\\", index);
if (indexOfEnd == -1) {
throw new DeserializeException(lineNumber, "\\X2\\ not closed with \\X0\\");
}
if ((indexOfEnd - index) % 4 != 0) {
throw new DeserializeException(lineNumber, "Number of hex chars in \\X2\\ definition not divisible by 4");
}
try {
ByteBuffer buffer = ByteBuffer.wrap(Hex.decodeHex(result.substring(index + 4, indexOfEnd).toCharArray()));
CharBuffer decode = Charsets.UTF_16BE.decode(buffer);
result = result.substring(0, index) + decode.toString() + result.substring(indexOfEnd + 4);
} catch (DecoderException e) {
throw new DeserializeException(lineNumber, e);
}
}
return result;
}
示例8: decodeHex
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
/**
* Hex解碼.
*/
public static byte[] decodeHex(String input) {
try {
return Hex.decodeHex(input.toCharArray());
} catch (DecoderException e) {
return "".getBytes();
}
}
示例9: test00ZAllBlocks
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
/**
* pulls all the blocks (slow) to check for full coverage.
*
* @throws ClientProtocolException
* if an error occurs.
* @throws IOException
* if an error occurs.
* @throws DecoderException
* if an error occurs.
* @throws InterruptedException
* if an error occurs.
*/
@Test
@Ignore
public void test00ZAllBlocks() throws ClientProtocolException, IOException, DecoderException, InterruptedException {
final BlockDb blockDb = new AbstractJsonMockBlockDb() {
@Override
public JSONArray getMockBlockDb() {
return new JSONArray();
}
};
final long maxBlockIx = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
final Set<TransactionType> knownTypeSet = new TreeSet<>();
for (long blockIx = 0; blockIx <= maxBlockIx; blockIx++) {
final Block block = blockDb.getFullBlockFromHeight(blockIx);
for (int txIx = 0; txIx < block.getTransactionList().size(); txIx++) {
final Transaction tx = block.getTransactionList().get(txIx);
if (!knownTypeSet.contains(tx.type)) {
LOG.error("getBlock {} {} tx {} {}", block.getIndexAsLong(), block.prevHash, txIx, tx.type);
knownTypeSet.add(tx.type);
}
}
}
blockDb.close();
}
示例10: testIPv6Mask120
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
@Test
public void testIPv6Mask120() throws InvalidKeyException, DecoderException {
final int mask = 120;
final IPPseudonymizer ipv6Pseudonymizer = IPPseudonymizer.initIPv6Pseudonymizer("3AE1E5F99DD4FF7196FE64ACDE688C89", mask);
final byte[] ip = Hex.decodeHex("97010a9b423def694d2aa231011d1210".toCharArray());
final byte[] newIp = ipv6Pseudonymizer.pseudonymize(ip.clone());
for (int i = 0; i < mask / 8; i++) {
assertThat(newIp[i], is(equalTo(ip[i])));
}
for (int i = mask / 8; i < 16; i++) {
assertThat(newIp[i], is(not(equalTo(ip[i]))));
}
}
示例11: testIPv6TCPDNS
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
@Test
public void testIPv6TCPDNS() throws IOException, DecoderException {
final ParseResult originalResult = Util.parse(_packetBytes, Ethernet2Frame.FORMAT);
final CopyTokenSerializer outSerializer = new CopyTokenSerializer(_packetBytes.length);
new Processor()
.addTransformer(new TransformConstraint(IPv6.FORMAT, TCP.FORMAT), "tcpchecksum", new IPv6TCPChecksumCalculator())
.transformAndProcess(originalResult, outSerializer);
final byte[] newBytes = outSerializer.outputData();
final ParseResult newResult = Util.parse(newBytes, Ethernet2Frame.FORMAT);
final ParseGraph originalValues = originalResult.environment.order;
final ParseGraph newValues = newResult.environment.order;
assertThat(originalValues.get("tcpchecksum").getValue(), is(equalTo(new byte[]{0x00, (byte) 0x00})));
assertThat(newValues.get("tcpchecksum").getValue(), is(equalTo(_checksum)));
}
示例12: testIPv4UDP
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
@Test
public void testIPv4UDP() throws IOException, DecoderException {
final byte[] bytes = _packetBytes;
final ParseResult originalResult = Util.parse(bytes, Ethernet2Frame.FORMAT);
final CopyTokenSerializer outSerializer = new CopyTokenSerializer(bytes.length);
new Processor()
.addTransformer(new TransformConstraint(IPv4.FORMAT, UDP.FORMAT), "udpchecksum", new IPv4UDPChecksumCalculator())
.transformAndProcess(originalResult, outSerializer);
final byte[] newBytes = outSerializer.outputData();
final ParseResult newResult = Util.parse(newBytes, Ethernet2Frame.FORMAT);
final ParseGraph originalValues = originalResult.environment.order;
final ParseGraph newValues = newResult.environment.order;
assertThat(originalValues.get("udpchecksum").getValue(), is(equalTo(new byte[]{0x00, (byte) 0x00})));
assertThat(newValues.get("udpchecksum").getValue(), is(equalTo(_checksum)));
}
示例13: test
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
public void test(final IPv6AddressPseudonymizer ipv6AddressPseudonymizer) throws IOException, DecoderException {
final byte[] bytes = Data.IPV6_UDP_MDNS;
final ParseResult originalResult = Util.parse(bytes, Ethernet2Frame.FORMAT);
assertTrue(originalResult.succeeded);
final TransformConstraint constraint = new TransformConstraint(IPv6.FORMAT);
final CopyTokenSerializer outSerializer = new CopyTokenSerializer(bytes.length);
new Processor()
.addTransformer(constraint, "sourceaddress", ipv6AddressPseudonymizer)
.addTransformer(constraint, "destinationaddress", ipv6AddressPseudonymizer)
.transformAndProcess(originalResult, outSerializer);
final byte[] newBytes = outSerializer.outputData();
final ParseResult newResult = Util.parse(newBytes, Ethernet2Frame.FORMAT);
assertTrue(newResult.succeeded);
final ParseGraph originalValues = originalResult.environment.order;
final ParseGraph newValues = newResult.environment.order;
assertThat(originalValues.get("sourceaddress").getValue(), is(equalTo(Hex.decodeHex("fe800000000000001cff02448da631d6".toCharArray()))));
assertThat(originalValues.get("destinationaddress").getValue(), is(equalTo(Hex.decodeHex("ff0200000000000000000000000000fb".toCharArray()))));
assertThat(newValues.get("sourceaddress").getValue(), is(equalTo(Hex.decodeHex("fe80000000000000b6de673148cda5be".toCharArray()))));
assertThat(newValues.get("destinationaddress").getValue(), is(equalTo(Hex.decodeHex("ff02000000000000f00dda65997efb75".toCharArray()))));
}
示例14: data
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
@Parameters(name = "FFX input: {0} - radix: {1} - bound: {2}")
public static Object[][] data() throws DecoderException {
return new Object[][]{
{new FFXInput(new byte[16], new byte[0]), 2, 512},
{new FFXInput(new byte[16], new byte[0]), 21, 128},
{new FFXInput(new byte[16], new byte[0]), 36, 64},
{new FFXInput(new byte[16], new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}), 13, 13000},
{new FFXInput(new byte[16], new byte[]{(byte) 0xC1, 24}), 17, 1024},
{new FFXInput(new byte[16], new byte[]{2}), 2, 1024},
{new FFXInput(new byte[]{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}, new byte[]{(byte) 0F, 32}), 22, 640},
{new FFXInput(new byte[]{(byte) 0xEF, 0x22, (byte) 0xA0, (byte) 0xA6, 0x79, 0x5D, (byte) 0xCC, 0x22, 0x12, (byte) 0xA1, 0x33, 0x12, (byte) 0xE9, 0x00, 0x10, 0x2E}, new byte[]{0, 0}), 2, 512},
{new FFXInput(new byte[]{0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, (byte) 0x89, (byte) 0x9A, (byte) 0xAB, (byte) 0xBC, (byte) 0xCD, (byte) 0xDE, (byte) 0xEF, (byte) 0xF0}, new byte[0]), 2, 512},
{new FFXInput(getRandomBytes(16), getRandomBytes(3)), 2, 512},
{new FFXInput(getRandomBytes(16), getRandomBytes(7)), 3, 12345},
{new FFXInput(getRandomBytes(16), getRandomBytes(0)), 17, 128},
{new FFXInput(getRandomBytes(16), getRandomBytes(18)), 24, 64},
{new FFXInput(getRandomBytes(16), getRandomBytes(2)), 31, 32}
};
}
示例15: verifyAccount
import org.apache.commons.codec.DecoderException; //導入依賴的package包/類
private void verifyAccount(Address address, JSONObject jsonAddress) throws Exception {
if(!jsonAddress.has(JSON_ADDRESS)) {
throw new DecoderException("property 'address' missing for chain address object in JSON object");
}
String jsonPath = jsonAddress.getString(JSON_PATH);
String jsonAddr = jsonAddress.getString(JSON_ADDRESS);
if(!jsonAddr.equals(address.getAddressString())) {
throw new DecoderException(String.format("JSON chain address does not match expected address. expected: %s, found %s",
address.getAddressString(), jsonAddr));
}
if(!jsonPath.equals(address.getPath())) {
throw new DecoderException(String.format("JSON chain path does not match expected path. expected: %s, found %s",
address.getPath(), jsonPath));
}
System.out.println(String.format("address successfully verified: %s %s", jsonPath, jsonAddr));
}