本文整理汇总了Java中org.apache.directory.api.util.Strings类的典型用法代码示例。如果您正苦于以下问题:Java Strings类的具体用法?Java Strings怎么用?Java Strings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Strings类属于org.apache.directory.api.util包,在下文中一共展示了Strings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
* |
* +--> LdapResult
* [+--> 0x8A L2 name
* [+--> 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
示例16: testResponseWithEmptyResponse
import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
* Test parsing of a response with empty Response
*/
@Test
public void testResponseWithEmptyResponse()
{
Dsmlv2ResponseParser parser = null;
try
{
parser = new Dsmlv2ResponseParser( getCodec() );
parser.setInput( ExtendedResponseTest.class.getResource( "response_with_empty_response.xml" ).openStream(),
"UTF-8" );
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
ExtendedResponseDsml extendedResponse = ( ExtendedResponseDsml ) parser.getBatchResponse().getCurrentResponse();
assertEquals( "", Strings.utf8ToString( extendedResponse.getResponseValue() ) );
}
开发者ID:apache,项目名称:directory-ldap-api,代码行数:26,代码来源:ExtendedResponseTest.java
示例17: deleteSchemaObjects
import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
* Delete all the schemaObjects for a given schema from the registries
*/
private void deleteSchemaObjects( Schema schema, Registries registries ) throws LdapException
{
Map<String, Set<SchemaObjectWrapper>> schemaObjects = registries.getObjectBySchemaName();
Set<SchemaObjectWrapper> content = schemaObjects.get( Strings.toLowerCaseAscii( schema.getSchemaName() ) );
List<SchemaObject> toBeDeleted = new ArrayList<>();
if ( content != null )
{
// Build an intermediate list to avoid concurrent modifications
for ( SchemaObjectWrapper schemaObjectWrapper : content )
{
toBeDeleted.add( schemaObjectWrapper.get() );
}
for ( SchemaObject schemaObject : toBeDeleted )
{
registries.delete( errors, schemaObject );
}
}
}
开发者ID:apache,项目名称:directory-ldap-api,代码行数:25,代码来源:DefaultSchemaManager.java
示例18: testAdDirSyncControl
import org.apache.directory.api.util.Strings; //导入依赖的package包/类
@Test
public void testAdDirSyncControl() throws Exception
{
ByteBuffer bb = ByteBuffer.allocate( 0x0F );
bb.put( new byte[]
{
0x30, 0x0D,
0x02, 0x02, 0x08, 0x01, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x02, 0x01, 0x00, // maxReturnLength (no limit)
0x04, 0x04, 'x', 'k', 'c', 'd' // the cookie
} );
bb.flip();
AdDirSync decorator = new AdDirSyncDecorator( codec );
AdDirSync adDirSync = ( AdDirSync ) ( ( AdDirSyncDecorator ) decorator ).decode( bb.array() );
assertEquals( EnumSet.of(
AdDirSyncFlag.LDAP_DIRSYNC_OBJECT_SECURITY,
AdDirSyncFlag.LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER ),
adDirSync.getFlags() );
assertEquals( 0, adDirSync.getMaxReturnLength() );
assertEquals( "xkcd", Strings.utf8ToString( adDirSync.getCookie() ) );
// test encoding
try
{
ByteBuffer buffer = ( ( AdDirSyncDecorator ) adDirSync ).encode( ByteBuffer
.allocate( ( ( AdDirSyncDecorator ) adDirSync ).computeLength() ) );
String expected = "0x30 0x0D 0x02 0x02 0x08 0x01 0x02 0x01 0x00 0x04 0x04 0x78 0x6B 0x63 0x64 ";
String decoded = Strings.dumpBytes( buffer.array() );
assertEquals( expected, decoded );
}
catch ( EncoderException e )
{
fail( e.getMessage() );
}
}
开发者ID:apache,项目名称:directory-ldap-api,代码行数:41,代码来源:AdDirSyncControlTest.java
示例19: isLDIFSafe
import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
* Checks if the input String contains only safe values, that is, the data
* does not need to be encoded for use with LDIF. The rules for checking safety
* are based on the rules for LDIF (LDAP Data Interchange Format) per RFC 2849.
* The data does not need to be encoded if all the following are true:
*
* The data cannot start with the following char values:
* <ul>
* <li>00 (NUL)</li>
* <li>10 (LF)</li>
* <li>13 (CR)</li>
* <li>32 (SPACE)</li>
* <li>58 (:)</li>
* <li>60 (<)</li>
* <li>Any character with value greater than 127</li>
* </ul>
*
* The data cannot contain any of the following char values:
* <ul>
* <li>00 (NUL)</li>
* <li>10 (LF)</li>
* <li>13 (CR)</li>
* <li>Any character with value greater than 127</li>
* </ul>
*
* The data cannot end with a space.
*
* @param str the String to be checked
* @return true if encoding not required for LDIF
*/
public static boolean isLDIFSafe( String str )
{
if ( Strings.isEmpty( str ) )
{
// A null string is LDIF safe
return true;
}
// Checking the first char
char currentChar = str.charAt( 0 );
if ( ( currentChar > 127 ) || !LDIF_SAFE_STARTING_CHAR_ALPHABET[currentChar] )
{
return false;
}
// Checking the other chars
for ( int i = 1; i < str.length(); i++ )
{
currentChar = str.charAt( i );
if ( ( currentChar > 127 ) || !LDIF_SAFE_OTHER_CHARS_ALPHABET[currentChar] )
{
return false;
}
}
// The String cannot end with a space
return currentChar != ' ';
}
开发者ID:apache,项目名称:directory-ldap-api,代码行数:61,代码来源:LdifUtils.java
示例20: LdapUrl
import org.apache.directory.api.util.Strings; //导入依赖的package包/类
/**
* Create a new LdapUrl from a String after having parsed it.
*
* @param string TheString that contains the LdapUrl
* @throws LdapURLEncodingException If the String does not comply with RFC 2255
*/
public LdapUrl( String string ) throws LdapURLEncodingException
{
if ( string == null )
{
throw new LdapURLEncodingException( I18n.err( I18n.ERR_04408 ) );
}
bytes = Strings.getBytesUtf8( string );
this.string = string;
parse( string.toCharArray() );
}
开发者ID:apache,项目名称:directory-ldap-api,代码行数:18,代码来源:LdapUrl.java
注:本文中的org.apache.directory.api.util.Strings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论