Example #1
0
 public byte[] getSaltBytes() {
   try {
     return Base64.decode(base64Salt, Base64.URL_SAFE);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
  /**
   * {@inheritDoc}
   *
   * @return GridCoverageReader.
   */
  @Override
  public GridCoverageReader convert(final ReferenceType source, final Map<String, Object> params)
      throws UnconvertibleObjectException {

    final InputStream stream = getInputStreamFromReference(source);

    String encoding = null;
    if (params != null && params.get(ENCODING) != null) {
      encoding = (String) params.get(ENCODING);
    }
    ImageInputStream imageStream = null;
    try {

      // decode form base64 stream
      if (encoding != null && encoding.equals(WPSEncoding.BASE64.getValue())) {
        final String encodedImage = IOUtilities.toString(stream);
        final byte[] byteData = Base64.decode(encodedImage.trim());
        if (byteData != null && byteData.length > 0) {
          try (InputStream is = new ByteArrayInputStream(byteData)) {
            imageStream = ImageIO.createImageInputStream(is);
          }
        }

      } else {
        imageStream = ImageIO.createImageInputStream(stream);
      }

      if (imageStream != null) {
        final ImageReader reader;
        if (source.getMimeType() != null) {
          reader = XImageIO.getReaderByMIMEType(source.getMimeType(), imageStream, null, null);
        } else {
          reader = XImageIO.getReader(imageStream, null, Boolean.FALSE);
        }
        return CoverageIO.createSimpleReader(reader);
      } else {
        throw new UnconvertibleObjectException("Error during image stream acquisition.");
      }

    } catch (MalformedURLException ex) {
      throw new UnconvertibleObjectException(
          "Reference grid coverage invalid input : Malformed url", ex);
    } catch (CoverageStoreException ex) {
      throw new UnconvertibleObjectException(
          "Reference grid coverage invalid input : Can't read coverage", ex);
    } catch (IOException ex) {
      throw new UnconvertibleObjectException("Reference grid coverage invalid input : IO", ex);
    } finally {
      if (imageStream != null) {
        try {
          imageStream.close();
        } catch (IOException ex) {
          LOGGER.log(Level.WARNING, "Error during release the image stream.", ex);
        }
      }
    }
  }
Example #3
0
 public static byte[] decode(String s) {
   s = s.replace('-', '+'); // 62nd char of encoding
   s = s.replace('_', '/'); // 63rd char of encoding
   switch (s.length() % 4) // Pad with trailing '='s
   {
     case 0:
       break; // No pad chars in this case
     case 2:
       s += "==";
       break; // Two pad chars
     case 3:
       s += "=";
       break; // One pad char
     default:
       throw new RuntimeException("Illegal base64url string!");
   }
   try {
     return Base64.decode(s);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  public void fromJson(ObjectNode node, IndexDefinitionImpl index) {
    IndexGeneralState state = IndexGeneralState.valueOf(JsonUtil.getString(node, "generalState"));
    IndexUpdateState updateState =
        IndexUpdateState.valueOf(JsonUtil.getString(node, "updateState"));
    IndexBatchBuildState buildState =
        IndexBatchBuildState.valueOf(JsonUtil.getString(node, "batchBuildState"));

    String queueSubscriptionId = JsonUtil.getString(node, "queueSubscriptionId", null);

    byte[] configuration;
    try {
      String configurationAsString = JsonUtil.getString(node, "configuration");
      configuration = Base64.decode(configurationAsString);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    byte[] shardingConfiguration = null;
    if (node.get("shardingConfiguration") != null) {
      String shardingConfAsString = JsonUtil.getString(node, "shardingConfiguration");
      try {
        shardingConfiguration = Base64.decode(shardingConfAsString);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }

    Map<String, String> solrShards = new HashMap<String, String>();
    ArrayNode shardsArray = JsonUtil.getArray(node, "solrShards");
    for (int i = 0; i < shardsArray.size(); i++) {
      ObjectNode shardNode = (ObjectNode) shardsArray.get(i);
      String shardName = JsonUtil.getString(shardNode, "name");
      String address = JsonUtil.getString(shardNode, "address");
      solrShards.put(shardName, address);
    }

    ActiveBatchBuildInfo activeBatchBuild = null;
    if (node.get("activeBatchBuild") != null) {
      ObjectNode buildNode = JsonUtil.getObject(node, "activeBatchBuild");
      activeBatchBuild = new ActiveBatchBuildInfo();
      activeBatchBuild.setJobId(JsonUtil.getString(buildNode, "jobId"));
      activeBatchBuild.setSubmitTime(JsonUtil.getLong(buildNode, "submitTime"));
      activeBatchBuild.setTrackingUrl(JsonUtil.getString(buildNode, "trackingUrl", null));
      activeBatchBuild.setBatchIndexConfiguration(
          serializeJsonNode(JsonUtil.getObject(buildNode, "batchIndexConfiguration")));
    }

    BatchBuildInfo lastBatchBuild = null;
    if (node.get("lastBatchBuild") != null) {
      ObjectNode buildNode = JsonUtil.getObject(node, "lastBatchBuild");
      lastBatchBuild = new BatchBuildInfo();
      lastBatchBuild.setJobId(JsonUtil.getString(buildNode, "jobId"));
      lastBatchBuild.setSubmitTime(JsonUtil.getLong(buildNode, "submitTime"));
      lastBatchBuild.setSuccess(JsonUtil.getBoolean(buildNode, "success"));
      lastBatchBuild.setJobState(JsonUtil.getString(buildNode, "jobState"));
      lastBatchBuild.setTrackingUrl(JsonUtil.getString(buildNode, "trackingUrl", null));
      ObjectNode countersNode = JsonUtil.getObject(buildNode, "counters");
      Iterator<String> it = countersNode.getFieldNames();
      while (it.hasNext()) {
        String key = it.next();
        long value = JsonUtil.getLong(countersNode, key);
        lastBatchBuild.addCounter(key, value);
      }
      lastBatchBuild.setBatchIndexConfiguration(
          serializeJsonNode(JsonUtil.getObject(buildNode, "batchIndexConfiguration")));
    }
    byte[] batchIndexConfiguration = null;
    if (node.get("batchIndexConfiguration") != null) {
      batchIndexConfiguration =
          serializeJsonNode(JsonUtil.getObject(node, "batchIndexConfiguration"));
    }
    byte[] defaultBatchIndexConfiguration = null;
    if (node.get("defaultBatchIndexConfiguration") != null) {
      defaultBatchIndexConfiguration =
          serializeJsonNode(JsonUtil.getObject(node, "defaultBatchIndexConfiguration"));
    }

    index.setGeneralState(state);
    index.setUpdateState(updateState);
    index.setBatchBuildState(buildState);
    index.setQueueSubscriptionId(queueSubscriptionId);
    index.setConfiguration(configuration);
    index.setSolrShards(solrShards);
    index.setShardingConfiguration(shardingConfiguration);
    index.setActiveBatchBuildInfo(activeBatchBuild);
    index.setLastBatchBuildInfo(lastBatchBuild);
    index.setBatchIndexConfiguration(batchIndexConfiguration);
    index.setDefaultBatchIndexConfiguration(defaultBatchIndexConfiguration);
  }
Example #5
0
 /**
  * Decode a PEM string to DER format
  *
  * @param pem
  * @return
  * @throws java.io.IOException
  */
 public static byte[] pemToDer(String pem) throws IOException {
   pem = removeBeginEnd(pem);
   return Base64.decode(pem);
 }