Package org.codehaus.preon.annotation

Examples of org.codehaus.preon.annotation.BoundString


    public <T> Codec<T> create(AnnotatedElement metadata, Class<T> type,
                               ResolverContext context) {
        if (metadata == null) {
            return null;
        }
        BoundString settings = metadata.getAnnotation(BoundString.class);
        if (String.class.equals(type) && settings != null) {
            try {
        Charset charset; // Encodings are now given as strings, and turned into Charsets
                charset = Charset.availableCharsets().get(settings.encoding());
                // This throws a NullPointerException if the Charset can't be found
                if (settings.size().length() > 0) {
                    Expression<Integer, Resolver> expr;
                    expr = Expressions.createInteger(context, settings.size());
                    return (Codec<T>) new FixedLengthStringCodec(
              charset, //Note that this is a Charset, not an Encoding
              expr,
              settings.match(),
              settings.converter().newInstance());
                } else {
                    return (Codec<T>) new NullTerminatedStringCodec(
              charset, //Note that this is a Charset, not an Encoding
              settings.match(),
              settings.converter().newInstance());
                }
            } catch (InstantiationException e) {
                throw new CodecConstructionException(e.getMessage());
            } catch (IllegalAccessException e) {
                throw new CodecConstructionException(e.getMessage());
View Full Code Here

TOP

Related Classes of org.codehaus.preon.annotation.BoundString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.