本文整理汇总了Java中org.apache.commons.codec.Encoder类的典型用法代码示例。如果您正苦于以下问题:Java Encoder类的具体用法?Java Encoder怎么用?Java Encoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Encoder类属于org.apache.commons.codec包,在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInvalidAuthenticationRequest
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
@Test
public void testInvalidAuthenticationRequest()
throws Exception
{
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI( "/feeds/unauthorized-repo" );
request.addHeader( "User-Agent", "Apache Archiva unit test" );
request.setMethod( "GET" );
Encoder encoder = new Base64();
String userPass = "unauthUser:unauthPass";
String encodedUserPass = new String( (byte[]) encoder.encode( userPass.getBytes() ) );
request.addHeader( "Authorization", "BASIC " + encodedUserPass );
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
rssFeedServlet.doGet( request, mockHttpServletResponse );
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
示例2: getEncoder
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
/** Must be thread-safe. */
protected Encoder getEncoder() {
// Unfortunately, Commons-Codec doesn't offer any thread-safe guarantees so we must play it safe and instantiate
// every time. A simple benchmark showed this as negligible.
try {
Encoder encoder = clazz.newInstance();
// Try to set the maxCodeLength
if(maxCodeLength != null && setMaxCodeLenMethod != null) {
setMaxCodeLenMethod.invoke(encoder, maxCodeLength);
}
return encoder;
} catch (Exception e) {
final Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e;
throw new IllegalArgumentException("Error initializing encoder: " + name + " / " + clazz, t);
}
}
示例3: testAsEncoder
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
@Test
public void testAsEncoder() throws EncoderException {
final Encoder encoder =
(Encoder) RareStringEncoderProxy.newInstance();
try {
encoder.encode(null);
Assert.fail("passed: <Object>encode(null)");
} catch (final NullPointerException npe) {
// expected
}
try {
encoder.encode(new Object());
Assert.fail("passed: encode(new Object())");
} catch (final EncoderException en) {
// expected;
}
final Object expected = "";
final Object actual = encoder.encode(expected);
Assert.assertEquals(actual, expected);
}
示例4: testAsEncoder
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
@Test
public void testAsEncoder() throws EncoderException {
final Encoder encoder = (Encoder) RareEncoderProxy.newInstance();
try {
encoder.encode(null);
Assert.fail("passed: <Object>encode(null)");
} catch (final NullPointerException npe) {
//expected
}
final Object expected = new Object();
final Object actual = encoder.encode(expected);
Assert.assertEquals(actual, expected);
}
示例5: testAsEncoder
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
@Test
public void testAsEncoder() throws EncoderException {
final Encoder encoder =
(Encoder) RareBinaryEncoderProxy.newInstance();
try {
encoder.encode(null);
Assert.fail("passed: <Object>encode(null)");
} catch (final NullPointerException npe) {
// expected
}
final Object expected = new byte[0];
final Object actual = encoder.encode(expected);
Assert.assertEquals(actual, expected);
}
示例6: getDefaultDeployment
import org.apache.commons.codec.Encoder; //导入依赖的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;
}
示例7: resolveEncoder
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
private Class<? extends Encoder> resolveEncoder(String name, ResourceLoader loader) {
String lookupName = name;
if (name.indexOf('.') == -1) {
lookupName = PACKAGE_CONTAINING_ENCODERS + name;
}
try {
return loader.newInstance(lookupName, Encoder.class).getClass();
} catch (RuntimeException e) {
throw new IllegalArgumentException("Error loading encoder '" + name + "': must be full class name or one of " + registry.keySet(), e);
}
}
示例8: testEmptyTerm
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
public void testEmptyTerm() throws IOException {
Encoder encoders[] = new Encoder[] {
new Metaphone(), new DoubleMetaphone(), new Soundex(), new RefinedSoundex(), new Caverphone2()
};
for (final Encoder e : encoders) {
Analyzer a = new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
Tokenizer tokenizer = new KeywordTokenizer(reader);
return new TokenStreamComponents(tokenizer, new PhoneticFilter(tokenizer, e, random().nextBoolean()));
}
};
checkOneTerm(a, "", "");
}
}
示例9: assertAlgorithm
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
static void assertAlgorithm(Encoder encoder, boolean inject, String input,
String[] expected) throws Exception {
Tokenizer tokenizer = new WhitespaceTokenizer(TEST_VERSION_CURRENT,
new StringReader(input));
PhoneticFilter filter = new PhoneticFilter(tokenizer, encoder, inject);
assertTokenStreamContents(filter, expected);
}
示例10: testEmptyTerm
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
public void testEmptyTerm() throws IOException {
Encoder encoders[] = new Encoder[] {
new Metaphone(), new DoubleMetaphone(), new Soundex(), new RefinedSoundex(), new Caverphone2()
};
for (final Encoder e : encoders) {
Analyzer a = new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
Tokenizer tokenizer = new KeywordTokenizer(reader);
return new TokenStreamComponents(tokenizer, new PhoneticFilter(tokenizer, e, random().nextBoolean()));
}
};
checkOneTermReuse(a, "", "");
}
}
示例11: testEncoder
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
/**
* Tests to make sure Base64's implementation of the org.apache.commons.codec.Encoder
* interface is behaving identical to commons-codec-1.3.jar.
*
* @throws EncoderException problem
*/
@Test
public void testEncoder() throws EncoderException {
final Encoder enc = 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(base64, (byte[]) enc.encode(binary));
assertTrue("Encoder test-" + i, b);
}
}
}
示例12: testAsEncoder
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
@Test
public void testAsEncoder() throws EncoderException {
final Encoder encoder = (Encoder) HexBinaryEncoderProxy.newInstance();
try {
encoder.encode(null);
Assert.fail("passed: <Object>encode(null)");
} catch (final NullPointerException npe) {
// expected
}
final Object decoded = Tests.decodedBytes();
final Object encoded = encoder.encode(decoded);
}
示例13: getHelperDeployment
import org.apache.commons.codec.Encoder; //导入依赖的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;
}
示例14: PhoneticFilter
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
/** Creates a PhoneticFilter with the specified encoder, and either
* adding encoded forms as synonyms (<code>inject=true</code>) or
* replacing them.
*/
public PhoneticFilter(TokenStream in, Encoder encoder, boolean inject) {
super(in);
this.encoder = encoder;
this.inject = inject;
}
示例15: assertAlgorithm
import org.apache.commons.codec.Encoder; //导入依赖的package包/类
static void assertAlgorithm(Encoder encoder, boolean inject, String input,
String[] expected) throws Exception {
Tokenizer tokenizer = new WhitespaceTokenizer(new StringReader(input));
PhoneticFilter filter = new PhoneticFilter(tokenizer, encoder, inject);
assertTokenStreamContents(filter, expected);
}