本文整理汇总了Java中org.apache.commons.codec.BinaryDecoder类的典型用法代码示例。如果您正苦于以下问题:Java BinaryDecoder类的具体用法?Java BinaryDecoder怎么用?Java BinaryDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryDecoder类属于org.apache.commons.codec包,在下文中一共展示了BinaryDecoder类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAsBinaryDecoder
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
@Test
public void testAsBinaryDecoder() throws DecoderException {
final BinaryDecoder decoder =
(BinaryDecoder) RareBinaryDecoderProxy.newInstance();
try {
decoder.decode((byte[]) null);
Assert.fail("passed.decode((byte[]) null)");
} catch (final NullPointerException npe) {
// expected
}
final byte[] expected = new byte[0];
final byte[] actual = decoder.decode(expected);
Assert.assertEquals(actual, expected);
}
示例2: testAsBinaryDecoder
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
@Test
public void testAsBinaryDecoder() throws DecoderException {
final BinaryDecoder decoder =
(BinaryDecoder) HexBinaryDecoderProxy.newInstance();
try {
decoder.decode((byte[]) null);
Assert.fail("decode((byte[]) null)");
} catch (final NullPointerException npe) {
// expected
}
final byte[] encoded = Tests.encodedBytes();
final byte[] decoded = decoder.decode(encoded);
}
示例3: getDefaultDeployment
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
protected static WebArchive getDefaultDeployment(TestContext context) {
context.setAppEngineWebXmlFile("appengine-web-with-logging-properties.xml");
WebArchive war = getTckDeployment(context);
war.addClasses(LoggingTestBase.class, TestBase.class)
// classes for Base64.isBase64()
.addClasses(Base64.class, BaseNCodec.class)
.addClasses(BinaryEncoder.class, Encoder.class)
.addClasses(BinaryDecoder.class, Decoder.class)
.addClasses(EncoderException.class, DecoderException.class)
.addAsWebInfResource("currentTimeUsec.jsp")
.addAsWebInfResource("doNothing.jsp")
.addAsWebInfResource("storeTestData.jsp")
.addAsWebInfResource("throwException.jsp")
.addAsWebInfResource("log4j-test.properties")
.addAsWebInfResource("logging-all.properties");
return war;
}
示例4: testBinaryDecoder
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
/**
* Tests to make sure Base64's implementation of the org.apache.commons.codec.BinaryDecoder
* interface is behaving identical to commons-codec-1.3.jar.
*
* @throws DecoderException problem
*/
@Test
public void testBinaryDecoder() throws DecoderException {
final BinaryDecoder dec = new Base64();
for (int i = 0; i < STRINGS.length; i++) {
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
final boolean b = Arrays.equals(binary, dec.decode(base64));
assertTrue("BinaryDecoder test-" + i, b);
}
}
}
示例5: doTest
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
private <TCoder extends BinaryEncoder & BinaryDecoder> void doTest(String plain, String key, String iv, TCoder coder)
{
AESCipher cipher = new AESCipher();
if (coder != null)
{
cipher.setCoder(coder);
}
cipher.setKey(key, iv);
// Encrypt.
String encrypted = cipher.encrypt(plain);
if (iv == null)
{
byte[] iv2 = cipher.getCipher().getIV();
cipher.setKey(key, iv2);
}
// Decrypt.
String decrypted = cipher.decrypt(encrypted);
if (DEBUG)
{
System.out.println("----------");
System.out.println("codec = " + ((coder != null) ? coder.getClass().getSimpleName() : "default"));
System.out.println("plain = " + plain);
System.out.println("encrypted = " + encrypted);
System.out.println("decrypted = " + decrypted);
}
assertNotEquals(plain, encrypted);
assertEquals(plain, decrypted);
}
示例6: getHelperDeployment
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
protected static WebArchive getHelperDeployment() {
WebArchive war = getTckDeployment();
war.addClass(DatastoreHelperTestBase.class)
.addClasses(Base64.class, BaseNCodec.class)
.addClasses(BinaryEncoder.class, Encoder.class)
.addClasses(BinaryDecoder.class, Decoder.class)
.addClasses(EncoderException.class, DecoderException.class);
return war;
}
示例7: CodecCipher
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
/**
* Constructor with a cipher, an encoder and a decoder.
*
* @param cipher
* A cipher. If {@code null} is given, {@link #setCipher(Cipher)}
* must be called later with a valid cipher.
*
* @param encoder
* An encoder used in {@link #encrypt(String)} and
* {@link #encrypt(byte[])} to encode an encrypted byte array.
* If {@code null} is given, {@link Base64} is used as the default
* encoder.
*
* @param decoder
* A decoder used in {@link #decrypt(String)} and
* {@link #decrypt(byte[])} to decode an encoded input byte array.
* If {@code null} is given, {@link Base64} is used as the default
* decoder.
*/
public CodecCipher(Cipher cipher, BinaryEncoder encoder, BinaryDecoder decoder)
{
this.cipher = cipher;
this.encoder = encoder;
this.decoder = decoder;
}
示例8: setDecoder
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
/**
* Set a decoder.
*
* @param decoder
* A decoder used by {@link #decrypt(String)} and
* {@link #decrypt(byte[])}.
*
* @return
* {@code this} object.
*/
public CodecCipher setDecoder(BinaryDecoder decoder)
{
this.decoder = decoder;
return this;
}
示例9: setCoder
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
/**
* Set a coder.
*
* @param coder
* A coder which works as both an encoder and a decoder.
* If {@code null} is given, {@link Base64} is used as the
* default coder.
*
* @return
* {@code this} object.
*/
public <TCoder extends BinaryEncoder & BinaryDecoder> CodecCipher setCoder(TCoder coder)
{
this.encoder = coder;
this.decoder = coder;
return this;
}
示例10: AESCipher
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
/**
* Constructor with an encoder and a decoder.
*
* <p>
* This constructor just performs {@link CodecCipher#CodecCipher(String,
* BinaryEncoder, BinaryDecoder) super("AES/CBC/PKCS5Padding", encoder, decoder)}.
* </p>
*
* @param encoder
* An encoder used in {@link #encrypt(String) encrypt(String)} and
* {@link #encrypt(byte[]) encrypt(byte[])} to encode an encrypted byte array.
* If {@code null} is given, {@link Base64} is used as the default
* encoder.
*
* @param decoder
* A decoder used in {@link #decrypt(String) decrypt(String)} and
* {@link #decrypt(byte[]) decrypt(byte[])} to decode an encoded input byte array.
* If {@code null} is given, {@link Base64} is used as the default
* decoder.
*/
public AESCipher(BinaryEncoder encoder, BinaryDecoder decoder)
{
super(TRANSFORMATION, encoder, decoder);
}
示例11: getDecoder
import org.apache.commons.codec.BinaryDecoder; //导入依赖的package包/类
/**
* Get the decoder which this instance internally holds.
*
* @return
* The internal decoder. This may be {@code null}, and
* in such a case, {@link #decrypt(String)} and
* {@link #decrypt(byte[])} use {@link Base64}.
*/
public BinaryDecoder getDecoder()
{
return decoder;
}