Creates a codec for both lookup and registration.

@param factory an identifier factory
@return a codec
967179
static Codec<NamingMessage> createFullCodec(final IdentifierFactory factory) {
    final Map<Class<? extends NamingMessage>, Codec<? extends NamingMessage>> clazzToCodecMap
        = new HashMap<>();
    clazzToCodecMap.put(NamingLookupRequest.class, new NamingLookupRequestCodec(factory));
    clazzToCodecMap.put(NamingLookupResponse.class, new NamingLookupResponseCodec(factory));
    clazzToCodecMap.put(NamingRegisterRequest.class, new NamingRegisterRequestCodec(factory));
    clazzToCodecMap.put(NamingRegisterResponse.class,
        new NamingRegisterResponseCodec(new NamingRegisterRequestCodec(factory)));
    clazzToCodecMap.put(NamingUnregisterRequest.class, new NamingUnregisterRequestCodec(factory));
    final Codec<NamingMessage> codec = new MultiCodec<>(clazzToCodecMap);
    return codec;
  }
761098
public void register(Object locator, IComponentFactory factory) {
		if (locator == null)
			throw new NullPointerException("Locator cannot be null");
		if (factory == null)
			throw new NullPointerException("Factory cannot be null");

		_registrations.add(new Registration(locator, factory));
	}
483093
@Nullable
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    private CodecType identifyCodecType(@NonNull MediaCodecInfo codecInfo) {

        final String name = codecInfo.getName();
        for (String token : AVC_TYPES) {
            if (name.contains(token)) {
                return CodecType.AVC;
            }
        }
        for (String token : H263_TYPES) {
            if (name.contains(token)) {
                return CodecType.H263;
            }
        }
        for (String token : MPEG4_TYPES) {
            if (name.contains(token)) {
                return CodecType.MPEG4;
            }
        }
        for (String token : AAC_TYPES) {
            if (name.contains(token)) {
                return CodecType.AAC;
            }
        }

        return null;
    }
391149
function codecFactory(injected) {

/* eslint-disable indent */
const sha256 = injected.sha256;

class AddressCodec {
  /* eslint-enable indent */

  constructor(alphabet) {
    this.alphabet = alphabet;
    this.codec = baseCodec(alphabet);
    this.base = alphabet.length;
  }

  encode(bytes, opts = {}) {
    const {version} = opts;
    return isSet(version) ?
              this.encodeVersioned(bytes, version, opts.expectedLength) :
           opts.checked ?
              this.encodeChecked(bytes) :
              this.encodeRaw(bytes);
  }

  decode(string, opts = {}) {
    const {version, versions} = opts;
    return isSet(versions) ?
              this.decodeMultiVersioned(
                  string, versions, opts.expectedLength, opts.versionTypes) :
           isSet(version) ?
              this.decodeVersioned(string, version, opts.expectedLength) :
           opts.checked ?
              this.decodeChecked(string) :
              this.decodeRaw(string);
  }

  encodeRaw(bytes) {
    return this.codec.encode(bytes);
  }

  decodeRaw(string) {
    return this.codec.decode(string);
  }

  encodeChecked(buffer) {
    const check = sha256(sha256(buffer)).slice(0, 4);
    return this.encodeRaw(concatArgs(buffer, check));
  }

  decodeChecked(encoded) {
    const buf = this.decodeRaw(encoded);
    if (buf.length < 5) {
      throw new Error('invalid_input_size');
    }
    if (!this.verifyCheckSum(buf)) {
      throw new Error('checksum_invalid');
    }
    return buf.slice(0, -4);
  }

  encodeVersioned(bytes, version, expectedLength) {
    if (expectedLength && bytes.length !== expectedLength) {
      throw new Error('unexpected_payload_length');
    }
    return this.encodeChecked(concatArgs(version, bytes));
  }

  decodeVersioned(string, version, expectedLength) {
    return this.decodeMultiVersioned(string, [version], expectedLength).bytes;
  }

  /**
  * @param {String} encoded - base58 checksum encoded data string
  * @param {Array} possibleVersions - array of possible versions.
  *                                   Each element could be a single byte or an
  *                                   array of bytes.
  * @param {Number} [expectedLength] - of decoded bytes minus checksum
  *
  * @param {Array} [types] - parrallel array of names matching possibleVersions
  *
  * @return {Object} -
  */
  decodeMultiVersioned(encoded, possibleVersions, expectedLength, types) {
    const withoutSum = this.decodeChecked(encoded);
    const ret = {version: null, bytes: null};

    if (possibleVersions.length > 1 && !expectedLength) {
      throw new Error('must pass expectedLengthgth > 1 possibleVersions');
    }

    const versionLenGuess = possibleVersions[0].length || 1; // Number.length
    const payloadLength = expectedLength ||
                                (withoutSum.length - versionLenGuess);
    const versionBytes = withoutSum.slice(0, -payloadLength);
    const payload = withoutSum.slice(-payloadLength);

    const foundVersion = possibleVersions.some(function(version, i) {
      const asArray = Array.isArray(version) ? version : [version];
      if (seqEqual(versionBytes, asArray)) {
        ret.version = version;
        ret.bytes = payload;
        if (types) {
          ret.type = types[i];
        }
        return true;
      }
    });

    if (!foundVersion) {
      throw new Error('version_invalid');
    }
    if (expectedLength && ret.bytes.length !== expectedLength) {
      throw new Error('unexpected_payload_length');
    }

    return ret;
  }

  verifyCheckSum(bytes) {
    const computed = sha256(sha256(bytes.slice(0, -4))).slice(0, 4);
    const checksum = bytes.slice(-4);
    return seqEqual(computed, checksum);
  }

  /**
  * @param {String} desiredPrefix - desired prefix when base58 encoded with
  *                                 checksum
  * @param {Number} payloadLength - number of bytes encoded not incl checksum
  * @return {Array} version
  */
  findPrefix(desiredPrefix, payloadLength) {
    if (this.base !== 58) {
      throw new Error('Only works for base58');
    }
    const totalLength = payloadLength + 4; // for checksum
    const chars = (Math.log(Math.pow(256, totalLength)) / Math.log(this.base));
     // (x, x.8] -> x+1, (x.8, x+1) -> x+2
    const requiredChars = Math.ceil(chars + 0.2);
    const padding = this.alphabet[Math.floor((this.alphabet.length) / 2) - 1];
    const template = desiredPrefix + new Array(requiredChars + 1).join(padding);
    const bytes = this.decodeRaw(template);
    const version = bytes.slice(0, -totalLength);
    return version;
  }
}

/* eslint-disable indent */
return AddressCodec;
/* eslint-enable indent */
}
668283
def RegisterFieldTypeCodec(encoder, decoder):
    """"""
    def Register(field_type):
        _FIELD_TYPE_CODECS[field_type] = _Codec(
            encoder=encoder, decoder=decoder)
        return field_type
    return Register
94586
protected void createEncoding() {
        if (encoding.startsWith("#")) {
            specialMap = new IntHashtable();
            StringTokenizer tok = new StringTokenizer(encoding.substring(1), " ,\t\n\r\f");
            if (tok.nextToken().equals("full")) {
                while (tok.hasMoreTokens()) {
                    String order = tok.nextToken();
                    String name = tok.nextToken();
                    char uni = (char)Integer.parseInt(tok.nextToken(), 16);
                    int orderK;
                    if (order.startsWith("'"))
                        orderK = order.charAt(1);
                    else
                        orderK = Integer.parseInt(order);
                    orderK %= 256;
                    specialMap.put(uni, orderK);
                    differences[orderK] = name;
                    unicodeDifferences[orderK] = uni;
                    widths[orderK] = getRawWidth(uni, name);
                    charBBoxes[orderK] = getRawCharBBox(uni, name);
                }
            }
            else {
                int k = 0;
                if (tok.hasMoreTokens())
                    k = Integer.parseInt(tok.nextToken());
                while (tok.hasMoreTokens() && k < 256) {
                    String hex = tok.nextToken();
                    int uni = Integer.parseInt(hex, 16) % 0x10000;
                    String name = GlyphList.unicodeToName(uni);
                    if (name != null) {
                        specialMap.put(uni, k);
                        differences[k] = name;
                        unicodeDifferences[k] = (char)uni;
                        widths[k] = getRawWidth(uni, name);
                        charBBoxes[k] = getRawCharBBox(uni, name);
                        ++k;
                    }
                }
            }
            for (int k = 0; k < 256; ++k) {
                if (differences[k] == null) {
                    differences[k] = notdef;
                }
            }
        }
        else if (fontSpecific) {
            for (int k = 0; k < 256; ++k) {
                widths[k] = getRawWidth(k, null);
                charBBoxes[k] = getRawCharBBox(k, null);
            }
        }
        else {
            String s;
            String name;
            char c;
            byte b[] = new byte[1];
            for (int k = 0; k < 256; ++k) {
                b[0] = (byte)k;
                s = PdfEncodings.convertToString(b, encoding);
                if (s.length() > 0) {
                    c = s.charAt(0);
                }
                else {
                    c = '?';
                }
                name = GlyphList.unicodeToName(c);
                if (name == null)
                    name = notdef;
                differences[k] = name;
                unicodeDifferences[k] = c;
                widths[k] = getRawWidth(c, name);
                charBBoxes[k] = getRawCharBBox(c, name);
            }
        }
    }
853941
public static <T> JsonCodec<T> create(Class<T> clazz) {
    return new JsonCodec<T>(clazz, DefaultGsonHolder.INSTANCE);
  }
5811
public static NlsMessageFactory getFactory() {

    if (factory == null) {
      synchronized (NlsAccess.class) {
        if (factory == null) {
          NlsMessageFactoryImpl factoryImpl = new NlsMessageFactoryImpl();
          factoryImpl.initialize();
          factory = factoryImpl;
        }
      }
    }
    return factory;
  }
292152
static synchronized BeanFactoryId register(Class<?> clazz, Set<String> pathParams,
                                               List<RequestObjectResolver> objectResolvers) {
        final BeanFactoryId beanFactoryId = new BeanFactoryId(clazz, pathParams);
        if (!factories.containsKey(beanFactoryId)) {
            final AnnotatedBeanFactory<Object> factory = createFactory(beanFactoryId, objectResolvers);
            if (factory != null) {
                factories.put(beanFactoryId, factory);
                logger.debug("Registered a bean factory: {}", beanFactoryId);
            } else {
                factories.put(beanFactoryId, unsupportedBeanFactory);
            }
        }
        return beanFactoryId;
    }
150754
public <A extends Annotation> void register(final Class<A> anno, final ConversionProcessorFactory<A> factory) {
        factoryMap.put(anno, factory);
    }
348527
protected static Factory createConfiguredFactory ()
    {
        String implClass;
        try {
            implClass = System.getProperty("com.samskivert.util.Log");
        } catch (SecurityException se) {
            // in a sandbox
            return null;
        }
        if (!StringUtil.isBlank(implClass)) {
            try {
                return (Factory)Class.forName(implClass).newInstance();
            } catch (Throwable t) {
                System.err.println("Unable to instantiate logging implementation: " + implClass);
                t.printStackTrace(System.err);
            }
        }
        return null;
    }
1082642
public HistogramDataPointCodec getCodec(final int id) {
    final HistogramDataPointCodec codec = codecs.get(id);
    if (codec == null) {
      throw new IllegalArgumentException("No codec found mapped to ID " + id);
    }
    return codec;
  }
1026521
public Factory registerObject(Object obj, ULocale locale, int kind, boolean visible) {
        Factory factory = new SimpleLocaleKeyFactory(obj, locale, kind, visible);
        return registerFactory(factory);
    }
279485
public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) {
        Directory dir = new RAMDirectory(ghLoc, true);
        StorableProperties properties = new StorableProperties(dir);
        if (!properties.loadExisting())
            throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: "
                    + dir.getLocation());

        // check encoding for compatibility
        properties.checkVersions(false);
        String acceptStr = properties.get("graph.flag_encoders");

        if (acceptStr.isEmpty())
            throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: "
                    + dir.getLocation());

        int bytesForFlags = 4;
        try {
            bytesForFlags = Integer.parseInt(properties.get("graph.bytes_for_flags"));
        } catch (NumberFormatException ex) {
        }
        return createBuilder(factory, acceptStr, bytesForFlags).build();
    }
680282
public boolean registerMap(MapSchema.MessageFactory factory)
    {
        return null == mapMapping.putIfAbsent(factory.typeClass().getName(),
                factory);
    }
263360
public final Factory registerFactory(Factory factory) {
        if (factory == null) {
            throw new NullPointerException();
        }
        try {
            factoryLock.acquireWrite();
            factories.add(0, factory);
            clearCaches();
        }
        finally {
            factoryLock.releaseWrite();
        }
        notifyChanged();
        return factory;
    }
415862
public static <T> Codec<T> create(Class<T> cls) {
        return create(cls, isDebugEnabled());
    }