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


Java Strings类代码示例

本文整理汇总了Java中org.apache.directory.api.util.Strings的典型用法代码示例。如果您正苦于以下问题:Java Strings类的具体用法?Java Strings怎么用?Java Strings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Strings类属于org.apache.directory.api.util包,在下文中一共展示了Strings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSerializeCompleteEntry

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Test the serialization of a complete entry
 */
@Test
public void testSerializeCompleteEntry() throws LdapException, IOException, ClassNotFoundException
{
    Dn dn = new Dn( schemaManager,  "ou=system" );

    byte[] password = Strings.getBytesUtf8( "secret" );
    Entry entry = new DefaultEntry( dn );
    entry.add( "ObjectClass", "top", "person" );
    entry.add( "cn", "test1" );
    entry.add( "userPassword", password );

    Entry entrySer = deserializeValue( serializeValue( entry ) );

    assertEquals( entry, entrySer );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:19,代码来源:SchemaAwareEntryTest.java

示例2: testBinaryAtavStaticSerializationBytes

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
@Ignore
@Test
public void testBinaryAtavStaticSerializationBytes() throws LdapException, IOException, ClassNotFoundException
{
    byte[] buffer = new byte[128];
    byte[] upValue = Strings.getBytesUtf8( "  Test  " );

    Ava atav = new Ava( schemaManager, "userPKCS12", upValue );

    int pos1 = atav.serialize( buffer, 0 );

    Ava atav2 = new Ava( schemaManager );
    int pos2 = atav2.deserialize( buffer, 0 );

    assertEquals( pos1, pos2 );
    assertEquals( atav, atav2 );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:18,代码来源:SchemaAwareAvaSerializationTest.java

示例3: getPbkdf2Credentials

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Gets the credentials from a PKCS5S2 hash.
 * The salt for PKCS5S2 hash is prepended to the password
 */
private static PasswordDetails getPbkdf2Credentials( byte[] credentials, int algoLength, LdapSecurityConstants algorithm )
{
    // The password is associated with a salt. Decompose it
    // in two parts, after having decoded the password.
    // The salt is at the *beginning* of the credentials, and is 16 bytes long
    // The algorithm, salt, and password will be stored into the PasswordDetails structure.
    byte[] passwordAndSalt = Base64
        .decode( Strings.utf8ToString( credentials, algoLength, credentials.length - algoLength ).toCharArray() );

    int saltLength = passwordAndSalt.length - PKCS5S2_LENGTH;
    byte[] salt = new byte[saltLength];
    byte[] password = new byte[PKCS5S2_LENGTH];

    split( passwordAndSalt, 0, salt, password );

    return new PasswordDetails( algorithm, salt, password );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:22,代码来源:PasswordUtil.java

示例4: computeLength

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Compute the ExtendedResponse length
 * <br>
 * ExtendedResponse :
 * <pre>
 * 0x78 L1
 *  |
 *  +--&gt; LdapResult
 * [+--&gt; 0x8A L2 name
 * [+--&gt; 0x8B L3 response]]
 * 
 * L1 = Length(LdapResult)
 *      [ + Length(0x8A) + Length(L2) + L2
 *       [ + Length(0x8B) + Length(L3) + L3]]
 * 
 * Length(ExtendedResponse) = Length(0x78) + Length(L1) + L1
 * </pre>
 * 
 * @return The ExtendedResponse length
 */
@Override
public int computeLength()
{
    int ldapResultLength = ( ( LdapResultDecorator ) getLdapResult() ).computeLength();

    extendedResponseLength = ldapResultLength;

    String id = getResponseName();

    if ( !Strings.isEmpty( id ) )
    {
        responseNameBytes = Strings.getBytesUtf8( id );
        int idLength = responseNameBytes.length;
        extendedResponseLength += 1 + TLV.getNbBytes( idLength ) + idLength;
    }

    byte[] encodedValue = getResponseValue();

    if ( encodedValue != null )
    {
        extendedResponseLength += 1 + TLV.getNbBytes( encodedValue.length ) + encodedValue.length;
    }

    return 1 + TLV.getNbBytes( extendedResponseLength ) + extendedResponseLength;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:46,代码来源:ExtendedResponseDecorator.java

示例5: action

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<SearchRequestDecorator> container ) throws DecoderException
{
    SearchRequestDecorator searchRequestDecorator = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    String attributeDescription = null;

    if ( tlv.getLength() != 0 )
    {
        attributeDescription = Strings.utf8ToString( tlv.getValue().getData() );

        // If the attributeDescription is empty, we won't add it
        if ( !Strings.isEmpty( attributeDescription.trim() ) )
        {
            searchRequestDecorator.getDecorated().addAttributes( attributeDescription );
        }
    }

    // We can have an END transition
    container.setGrammarEndAllowed( true );

    if ( IS_DEBUG )
    {
        LOG.debug( "Decoded Attribute Description : {}", attributeDescription );
    }
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:29,代码来源:StoreSearchRequestAttributeDesc.java

示例6: testIsValid

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Test the isValid method
 * 
 * The SyntaxChecker does not accept values longer than 5 chars.
 */
@Test
public void testIsValid() throws LdapInvalidAttributeValueException
{
    AttributeType attribute = EntryUtils.getBytesAttributeType();

    new Value( attribute, ( byte[] ) null );
    new Value( attribute, Strings.EMPTY_BYTES );
    new Value( attribute, new byte[]
        { 0x01, 0x02 } );

    try
    {
        new Value( attribute, new byte[]
            { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 } );
        fail();
    }
    catch ( LdapInvalidAttributeValueException liave )
    {
        assertTrue( true );
    }
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:27,代码来源:BinaryValueAttributeTypeTest.java

示例7: testIsValidSyntaxChecker

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
@Test
public void testIsValidSyntaxChecker() throws LdapException
{
    Value bv = new Value( ( byte[] ) null );

    assertTrue( bv.isValid( BINARY_CHECKER ) );

    bv = new Value( Strings.EMPTY_BYTES );
    assertTrue( bv.isValid( BINARY_CHECKER ) );

    bv = new Value( BYTES1 );
    assertTrue( bv.isValid( BINARY_CHECKER ) );

    bv = new Value( INVALID_BYTES );
    assertFalse( bv.isValid( BINARY_CHECKER ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:17,代码来源:BinaryValueTest.java

示例8: testDecodeRespWithoutWarningAndError

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
@Test
public void testDecodeRespWithoutWarningAndError() throws Exception
{
    ByteBuffer bb = ByteBuffer.allocate( 2 );

    bb.put( new byte[]
        {
            0x30, 0x00
    } );

    bb.flip();

    PasswordPolicyDecorator control = new PasswordPolicyDecorator( codec, true );
    PasswordPolicy passwordPolicy = ( PasswordPolicy ) control.decode( bb.array() );

    assertNotNull( passwordPolicy );
    assertTrue( passwordPolicy.hasResponse() );

    ByteBuffer encoded = ( ( PasswordPolicyDecorator ) passwordPolicy ).encode(
        ByteBuffer.allocate( ( ( PasswordPolicyDecorator ) passwordPolicy ).computeLength() ) );
    assertEquals( Strings.dumpBytes( bb.array() ), Strings.dumpBytes( encoded.array() ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:23,代码来源:PasswordPolicyTest.java

示例9: testNormalize

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
@Test
public void testNormalize() throws LdapException
{
    Value bv = new Value( ( byte[] ) null );

    bv = new Value( at, bv );
    assertTrue( bv.isSchemaAware() );
    assertEquals( null, bv.getBytes() );

    bv = new Value( Strings.EMPTY_BYTES );
    bv = new Value( at, bv );
    assertTrue( bv.isSchemaAware() );
    assertTrue( Arrays.equals( Strings.EMPTY_BYTES, bv.getBytes() ) );

    bv = new Value( BYTES2 );
    bv = new Value( at, bv );
    assertTrue( bv.isSchemaAware() );
    assertTrue( Arrays.equals( BYTES2, bv.getBytes() ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:20,代码来源:BinaryValueTest.java

示例10: testEncodeProxiedUserAuthzControl

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Test encoding of a ProxiedAuthzControl.
 */
@Test
public void testEncodeProxiedUserAuthzControl() throws Exception
{
    ByteBuffer bb = ByteBuffer.allocate( 0x0C );
    bb.put( new byte[]
        {
            // ProxiedAuthzNotification ::= u:elecharny
            'u', ':', 'e', 'l', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'
    } );

    String expected = Strings.dumpBytes( bb.array() );
    bb.flip();

    ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );

    ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.getDecorated();
    proxiedAuthz.setAuthzId( "u:el\u00e9charny" );
    bb = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
    String decoded = Strings.dumpBytes( bb.array() );
    assertEquals( expected, decoded );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:25,代码来源:ProxiedAuthzControlTest.java

示例11: testEncodeProxiedAnonymousAuthzControl

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Test encoding of a ProxiedAuthzControl.
 */
@Test
public void testEncodeProxiedAnonymousAuthzControl() throws Exception
{
    ByteBuffer bb = ByteBuffer.allocate( 0x00 );
    bb.put( new byte[]
        {
            // ProxiedAuthzNotification ::= anonymous
    } );

    String expected = Strings.dumpBytes( bb.array() );
    bb.flip();

    ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );

    ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.getDecorated();
    proxiedAuthz.setAuthzId( "" );
    bb = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
    String decoded = Strings.dumpBytes( bb.array() );
    assertEquals( expected, decoded );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:24,代码来源:ProxiedAuthzControlTest.java

示例12: action

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<BindRequestDecorator> container ) throws DecoderException
{
    BindRequest bindRequestMessage = container.getMessage();

    // Get the Value and store it in the BindRequest
    TLV tlv = container.getCurrentTLV();

    // We have to handle the special case of a 0 length name
    if ( tlv.getLength() == 0 )
    {
        bindRequestMessage.setName( "" );
    }
    else
    {
        byte[] nameBytes = tlv.getValue().getData();
        String nameStr = Strings.utf8ToString( nameBytes );
        bindRequestMessage.setName( nameStr );
    }

    if ( IS_DEBUG )
    {
        LOG.debug( " The Bind name is {}", bindRequestMessage.getName() );
    }
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:28,代码来源:StoreName.java

示例13: setCookie

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void setCookie( byte[] cookie )
{
    // Copy the bytes
    if ( !Strings.isEmpty( cookie ) )
    {
        byte[] copy = new byte[cookie.length];
        System.arraycopy( cookie, 0, copy, 0, cookie.length );
        getDecorated().setCookie( copy );
    }
    else
    {
        getDecorated().setCookie( null );
    }
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:19,代码来源:SyncDoneValueDecorator.java

示例14: testResponseWithResponse

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Test parsing of a response with Response
 */
@Test
public void testResponseWithResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( ExtendedResponseTest.class.getResource( "response_with_response.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ExtendedResponseDsml extendedResponse = ( ExtendedResponseDsml ) parser.getBatchResponse().getCurrentResponse();

    assertEquals( "This is a response", Strings.utf8ToString( extendedResponse.getResponseValue() ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:26,代码来源:ExtendedResponseTest.java

示例15: testResponseWithBase64Response

import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
 * Test parsing of a response with Base64 Response
 */
@Test
public void testResponseWithBase64Response()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            ExtendedResponseTest.class.getResource( "response_with_base64_response.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ExtendedResponseDsml extendedResponse = ( ExtendedResponseDsml ) parser.getBatchResponse().getCurrentResponse();

    assertEquals( "DSMLv2.0 rocks!!", Strings.utf8ToString( extendedResponse.getResponseValue() ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:26,代码来源:ExtendedResponseTest.java


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