Get the code from a {@link CoordinateReferenceSystem}.

@param crs the crs to get the code from.

@return the code, that can be used with {@link CRS#decode(String)} to recreate the crs.

@throws Exception
333240
public static String getCodeFromCrs( CoordinateReferenceSystem crs ) throws Exception {
        String code = null;
        try {
            Integer epsg = CRS.lookupEpsgCode(crs, true);
            code = "EPSG:" + epsg; //$NON-NLS-1$
        } catch (Exception e) {
            // try non epsg
            code = CRS.lookupIdentifier(crs, true);
        }
        return code;
    }
1303082
public static CRLReason getRevocationReason(X509CRLEntry crlEntry) {
        try {
            byte[] ext = crlEntry.getExtensionValue("2.5.29.21");
            if (ext == null) {
                return null;
            }
            DerValue val = new DerValue(ext);
            byte[] data = val.getOctetString();

            CRLReasonCodeExtension rcExt =
                new CRLReasonCodeExtension(Boolean.FALSE, data);
            return rcExt.getReasonCode();
        } catch (IOException ioe) {
            return null;
        }
    }
613700
public SpatialReferenceSystem getOrCreateCode(String organization,
			long coordsysId) throws SQLException {

		SpatialReferenceSystem srs = queryForOrganizationCoordsysId(
				organization, coordsysId);

		srs = createIfNeeded(srs, organization, coordsysId);

		return srs;
	}
149662
public static CoordinateReferenceSystem parseProjection(
            final String projection, final Boolean longitudeFirst) {
        try {
            if (longitudeFirst == null) {
                return CRS.decode(projection);
            } else {
                return CRS.decode(projection, longitudeFirst);
            }
        } catch (NoSuchAuthorityCodeException e) {
            throw new RuntimeException(projection + " was not recognized as a crs code", e);
        } catch (FactoryException e) {
            throw new RuntimeException("Error occurred while parsing: " + projection, e);
        }
    }
785432
public static sslcrl get(nitro_service service, String crlname) throws Exception{
		sslcrl obj = new sslcrl();
		obj.set_crlname(crlname);
		sslcrl response = (sslcrl) obj.get_resource(service);
		return response;
	}
269876
@Override
	public void afterPropertiesSet() throws Exception {
		if (cdxSource == null) {
			cdxSource = zipnumSource;
		}

		cdxLineFactory = new StandardCDXLineFactory(cdxFormat);
		// defaultCdxFormat = cdxLineFactory.getParseFormat();

		// if (authChecker != null && authChecker.getPublicCdxFields() != null)
		// {
		// publicCdxFields = new
		// FieldSplitFormat(authChecker.getPublicCdxFields());
		// }

		if (defaultParams == null) {
			defaultParams = new ZipNumParams(maxPageSize, maxPageSize, 0, false);
		}

		super.afterPropertiesSet();
	}
1109334
public static byte[] getEncodedInternal(X509CRL crl) throws CRLException {
        if (crl instanceof X509CRLImpl) {
            return ((X509CRLImpl)crl).getEncodedInternal();
        } else {
            return crl.getEncoded();
        }
    }
998988
protected Method getParse(Class cls) throws Exception {
    Method meth = methodCache.get(cls);
    if (null == meth) {
      meth = cls.getMethod("parseFrom", new Class[]{ byte[].class });
      methodCache.put(cls, meth);
    }
    return meth;
  }
565421
static Object decode(String s) {
    byte[] bytes = Base64.base64ToByteArray(s);
    ObjectInputStream objectInputStream;
    try {
      objectInputStream = new ObjectInputStream(
          new ByteArrayInputStream(bytes));
      return objectInputStream.readObject();
    } catch (IOException | ClassNotFoundException e) {
      log.error(e);
      return null;
    }
  }
516064
public void decode(AsnInputStream ais) throws ParseException {
        try {
            AsnInputStream localAis = ais.readSequenceStream();
            int tag = localAis.readTag();
            if (tag != Tag.OBJECT_IDENTIFIER || localAis.getTagClass() != Tag.CLASS_UNIVERSAL)
                throw new ParseException(PAbortCauseType.IncorrectTxPortion, null,
                        "Error decoding ApplicationContextName: bad tag or tagClass, found tag=" + tag + ", tagClass="
                                + localAis.getTagClass());
            this.oid = localAis.readObjectIdentifier();

        } catch (IOException e) {
            throw new ParseException(PAbortCauseType.BadlyFormattedTxPortion, null,
                    "IOException while decoding ApplicationContextName: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new ParseException(PAbortCauseType.BadlyFormattedTxPortion, null,
                    "AsnException while decoding ApplicationContextName: " + e.getMessage(), e);
        }

    }
206246
public static String urlDecode(String s) {
        try {
            return URLDecoder.decode(s, StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("get a jdk that actually supports utf-8", e);
        }
    }
395874
private List<String> getCrlDistributionPoints(X509Certificate cert) throws CertificateVerificationException {

        //Gets the DER-encoded OCTET string for the extension value for CRLDistributionPoints.
        byte[] crlDPExtensionValue = cert.getExtensionValue(Extension.cRLDistributionPoints.getId());
        if (crlDPExtensionValue == null) {
            throw new CertificateVerificationException("Certificate doesn't have CRL distribution points");
        }
        //crlDPExtensionValue is encoded in ASN.1 format.
        ASN1InputStream asn1In = new ASN1InputStream(crlDPExtensionValue);
        //DER (Distinguished Encoding Rules) is one of ASN.1 encoding rules defined in ITU-T X.690, 2002, specification.
        //ASN.1 encoding rules can be used to encode any data object into a binary file. Read the object in octets.
        CRLDistPoint distPoint;
        try {
            DEROctetString crlDEROctetString = (DEROctetString) asn1In.readObject();
            //Get Input stream in octets.
            distPoint = getOctetInputStream(crlDEROctetString);
        } catch (IOException e) {
            throw new CertificateVerificationException("Cannot read certificate to get CRL URLs", e);
        } finally {
            try {
                asn1In.close();
            } catch (IOException e) {
                LOG.error("Cannot close input stream", e);
            }
        }

        List<String> crlUrls = new ArrayList<>();
        //Loop through ASN1Encodable DistributionPoints.
        for (DistributionPoint dp : distPoint.getDistributionPoints()) {
            //get ASN1Encodable DistributionPointName.
            DistributionPointName dpn = dp.getDistributionPoint();
            if (dpn != null && dpn.getType() == DistributionPointName.FULL_NAME) {
                //Create ASN1Encodable General Names.
                GeneralName[] genNames = GeneralNames.getInstance(dpn.getName()).getNames();
                // Look for a URI
                for (GeneralName genName : genNames) {
                    if (genName.getTagNo() == GeneralName.uniformResourceIdentifier) {
                        //DERIA5String contains an ascii string.
                        //A IA5String is a restricted character string type in the ASN.1 notation.
                        String url = DERIA5String.getInstance(genName.getName()).getString().trim();
                        crlUrls.add(url);
                    }
                }
            }
        }

        if (crlUrls.isEmpty()) {
            throw new CertificateVerificationException("Cant get CRL urls from certificate");
        }
        return crlUrls;
    }
777077
public void decode(AsnInputStream ais) throws ParseException {

        this.correlationId = null;
        this.correlationInvoke = null;
        this.operationCode = null;
        this.parameter = null;

        try {
            if (ais.getTag() == Invoke._TAG_INVOKE_NOT_LAST)
                this.setNotLast(true);
            else
                this.setNotLast(false);

            AsnInputStream localAis = ais.readSequenceStream();

            // invokeId & correlationId
            byte[] buf = TcapFactory.readComponentId(localAis, 0, 2);
            if (buf.length >= 1)
                this.setInvokeId((long) buf[0]);
            if (buf.length >= 2)
                this.setCorrelationId((long) buf[1]);

            // operationCode
            if (localAis.available() == 0)
                throw new ParseException(RejectProblem.generalBadlyStructuredCompPortion, "OperationCode is not found when decoding Invoke");
            int tag = localAis.readTag();
            if ((tag != OperationCode._TAG_NATIONAL && tag != OperationCode._TAG_PRIVATE) || localAis.getTagClass() != Tag.CLASS_PRIVATE
                    || !localAis.isTagPrimitive()) {
                throw new ParseException(RejectProblem.generalIncorrectComponentPortion,
                        "OperationCode in Invoke has bad tag or tag class or is not primitive: tag=" + tag + ", tagClass=" + localAis.getTagClass());
            }
            this.operationCode = TcapFactory.createOperationCode(localAis);

            // Parameter
            this.parameter = TcapFactory.readParameter(localAis);
        } catch (IOException e) {
            throw new ParseException(RejectProblem.generalBadlyStructuredCompPortion,
                    "IOException while decoding Invoke: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new ParseException(RejectProblem.generalBadlyStructuredCompPortion,
                    "AsnException while decoding Invoke: " + e.getMessage(), e);
        } catch (ParseException e) {
            e.setInvokeId(this.invokeId);
            throw e;
        }
    }
1354337
@SuppressWarnings("unchecked")
    public static Reference toReference(Vector<Object> xmlRpcParameters)
    {
        Reference reference = null;
        if(!xmlRpcParameters.isEmpty())
        {
            Requirement requirement = toRequirement((Vector<Object>)xmlRpcParameters.get(REFERENCE_REQUIREMENT_IDX));
            Specification specification = toSpecification((Vector<Object>)xmlRpcParameters.get(REFERENCE_SPECIFICATION_IDX));
            SystemUnderTest sut = toSystemUnderTest((Vector<Object>)xmlRpcParameters.get(REFERENCE_SUT_IDX));
            String sections = toNullIfEmpty((String)xmlRpcParameters.get(REFERENCE_SECTIONS_IDX));
            reference = Reference.newInstance(requirement, specification, sut, sections);
            Execution exe = toExecution((Vector<Object>)xmlRpcParameters.get(REFERENCE_LAST_EXECUTION_IDX));
            reference.setLastExecution(exe);
        }

        return reference;
    }
238059
public void decode(AsnInputStream ais) throws ParseException {

        this.correlationId = null;
        this.parameter = null;

        try {
            AsnInputStream localAis = ais.readSequenceStream();

            // correlationId
            byte[] buf = TcapFactory.readComponentId(localAis, 1, 1);
            this.setCorrelationId((long) buf[0]);

            // Parameter
            this.parameter = TcapFactory.readParameter(localAis);

        } catch (IOException e) {
            throw new ParseException(RejectProblem.generalBadlyStructuredCompPortion, "IOException while decoding ReturnResult: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new ParseException(RejectProblem.generalBadlyStructuredCompPortion, "AsnException while decoding ReturnResult: " + e.getMessage(), e);
        } catch (ParseException e) {
            e.setInvokeId(this.correlationId);
            throw e;
        }
    }
513751
public MathTransform calculateLabelTransform(final CoordinateReferenceSystem mapCrs) {
        MathTransform labelTransform;
        if (this.labelProjection != null) {
            try {
                labelTransform = CRS.findMathTransform(mapCrs, this.labelCRS, true);
            } catch (FactoryException e) {
                throw new RuntimeException(e);
            }
        } else {
            labelTransform = IdentityTransform.create(2);
        }

        return labelTransform;
    }
857477
public static Geometry ST_Transform(Connection connection, Geometry geom, Integer codeEpsg) throws SQLException, CoordinateOperationException {
        if (geom == null) {
            return null;
        }
        if (codeEpsg == null) {
            throw new IllegalArgumentException("The SRID code cannot be null.");
        }
        if (crsf == null) {
            crsf = new CRSFactory();
            //Activate the CRSFactory and the internal H2 spatial_ref_sys registry to
            // manage Coordinate Reference Systems.
            crsf.getRegistryManager().addRegistry(srr);
        }
        srr.setConnection(connection);
        try {
            int inputSRID = geom.getSRID();
            if (inputSRID == 0) {
                throw new SQLException("Cannot find a CRS");
            } else {
                CoordinateReferenceSystem inputCRS = crsf.getCRS(srr.getRegistryName() + ":" + String.valueOf(inputSRID));
                CoordinateReferenceSystem targetCRS = crsf.getCRS(srr.getRegistryName() + ":" + String.valueOf(codeEpsg));
                if (inputCRS.equals(targetCRS)) {
                    return geom;
                }
                EPSGTuple epsg = new EPSGTuple(inputSRID, codeEpsg);
                CoordinateOperation op = copPool.get(epsg);
                if (op != null) {
                    Geometry outPutGeom = geom.copy();
                    outPutGeom.geometryChanged();
                    outPutGeom.apply(new CRSTransformFilter(op));
                    outPutGeom.setSRID(codeEpsg);
                    return outPutGeom;
                } else {
                    if (inputCRS instanceof GeodeticCRS && targetCRS instanceof GeodeticCRS) {
                        Set<CoordinateOperation> ops = CoordinateOperationFactory
                                .createCoordinateOperations((GeodeticCRS) inputCRS, (GeodeticCRS) targetCRS);
                        if (!ops.isEmpty()) {
                            op = CoordinateOperationFactory.getMostPrecise(ops);
                            Geometry outPutGeom = (Geometry) geom.copy();
                            outPutGeom.geometryChanged();
                            outPutGeom.apply(new CRSTransformFilter(op));
                            copPool.put(epsg, op);
                            outPutGeom.setSRID(codeEpsg);
                            return outPutGeom;
                        }
                    } else {
                        throw new SQLException("The transformation from "
                                + inputCRS + " to " + codeEpsg + " is not yet supported.");
                    }
                }
            }
        } catch (CRSException ex) {
            throw new SQLException("Cannot create the CRS", ex);
        } finally {
            srr.setConnection(null);
        }
        return null;

    }