当前位置: 首页>>代码示例>>Java>>正文


Java Encoder类代码示例

本文整理汇总了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() );

}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:22,代码来源:RssFeedServletTest.java

示例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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:PhoneticFilterFactory.java

示例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);
}
 
开发者ID:jinahya,项目名称:commons-codec-proxies,代码行数:25,代码来源:RareStringEncoderProxyTest.java

示例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);
}
 
开发者ID:jinahya,项目名称:commons-codec-proxies,代码行数:17,代码来源:RareEncoderProxyTest.java

示例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);
}
 
开发者ID:jinahya,项目名称:commons-codec-proxies,代码行数:18,代码来源:RareBinaryEncoderProxyTest.java

示例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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:18,代码来源:LoggingTestBase.java

示例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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:PhoneticFilterFactory.java

示例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, "", "");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:TestPhoneticFilter.java

示例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);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:8,代码来源:TestPhoneticFilter.java

示例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, "", "");
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:16,代码来源:TestPhoneticFilter.java

示例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);
        }
    }
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-codec,代码行数:19,代码来源:Base64Codec13Test.java

示例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);
}
 
开发者ID:jinahya,项目名称:hex-codec,代码行数:16,代码来源:HexBinaryEncoderProxyTest.java

示例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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:10,代码来源:DatastoreHelperTestBase.java

示例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;   
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:PhoneticFilter.java

示例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);
}
 
开发者ID:europeana,项目名称:search,代码行数:7,代码来源:TestPhoneticFilter.java


注:本文中的org.apache.commons.codec.Encoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。