List of usage examples for javax.xml.bind DatatypeConverter parseBase64Binary
public static byte[] parseBase64Binary(String lexicalXSDBase64Binary)
Converts the string argument into an array of bytes.
From source file:fr.inria.oak.paxquery.pact.operators.binary.ConjLNOEquiJoinWithAggregationOperator.java
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); this.aggregationColumn = parameters.getInteger(PACTOperatorsConfiguration.AGGREGATION_COLUMN_INT.toString(), -1);// w w w . ja va 2s .c o m String aggregationTypeEncoded = parameters .getString(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(), null); byte[] aggregationTypeBytes = DatatypeConverter.parseBase64Binary(aggregationTypeEncoded); final AggregationType aggregationType = (AggregationType) SerializationUtils .deserialize(aggregationTypeBytes); this.aggregationType = aggregationType; this.excludeNestedField = parameters .getBoolean(PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(), false); }
From source file:fr.inria.oak.paxquery.pact.operators.unary.GroupByWithAggregationOperator.java
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); this.aggregationColumn = parameters.getInteger(PACTOperatorsConfiguration.AGGREGATION_COLUMN_INT.toString(), -1);/*from w ww . j a v a2s . c o m*/ String aggregationTypeEncoded = parameters .getString(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(), null); byte[] aggregationTypeBytes = DatatypeConverter.parseBase64Binary(aggregationTypeEncoded); final AggregationType aggregationType = (AggregationType) SerializationUtils .deserialize(aggregationTypeBytes); this.aggregationType = aggregationType; this.excludeNestedField = parameters .getBoolean(PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(), false); this.attachDummyColumn = parameters .getBoolean(PACTOperatorsConfiguration.ATTACH_DUMMY_COLUMN_BOOLEAN.toString(), false); }
From source file:io.lightlink.types.BlobConverter.java
@Override public Object convertToJdbc(Connection connection, RunnerContext runnerContext, String name, Object value) throws IOException { if (value == null) return null; if (value instanceof InputStream && StringUtils.isBlank(encoding)) { return value; } else {/*from w w w . j a va 2s . c o m*/ byte[] array; if (value instanceof byte[]) { array = (byte[]) value; } else if (value instanceof InputStream) { array = IOUtils.toByteArray((InputStream) value); } else if (value instanceof String) { String str = (String) value; if (encoding.equalsIgnoreCase("base64")) array = DatatypeConverter.parseBase64Binary(str); else try { array = str.getBytes(encoding); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( "Cannot convert value:" + value + " to Blob. Specified encoding:" + encoding + " not recognised. (note:default encoding for String is base64)"); } } else { throw new IllegalArgumentException("Cannot convert value:" + value + " of type:" + value.getClass().getName() + " to Blob. int[] or String expected. (note:default encoding for String is base64)"); } return new ByteArrayInputStream(array); } }
From source file:com.uber.hoodie.common.BloomFilter.java
/** * Create the bloom filter from serialized string. *//*from www . ja va 2s. c om*/ public BloomFilter(String filterStr) { this.filter = new org.apache.hadoop.util.bloom.BloomFilter(); byte[] bytes = DatatypeConverter.parseBase64Binary(filterStr); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); try { this.filter.readFields(dis); dis.close(); } catch (IOException e) { throw new HoodieIndexException("Could not deserialize BloomFilter instance", e); } }
From source file:fr.inria.oak.paxquery.pact.io.XmlOutputFormat.java
@Override public void configure(Configuration parameters) { super.configure(parameters); // read your own parameters String recordsSignatureEncoded = parameters.getString(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), null);//from ww w. j a v a 2 s. c o m byte[] recordsSignatureBytes = DatatypeConverter.parseBase64Binary(recordsSignatureEncoded); final NestedMetadata signature = (NestedMetadata) SerializationUtils.deserialize(recordsSignatureBytes); this.signature = signature; String applyConstructEncoded = parameters .getString(PACTOperatorsConfiguration.APPLY_CONSTRUCT_BINARY.toString(), null); byte[] applyConstructBytes = DatatypeConverter.parseBase64Binary(applyConstructEncoded); final ApplyConstruct apply = (ApplyConstruct) SerializationUtils.deserialize(applyConstructBytes); this.apply = apply; }
From source file:com.github.sdbg.debug.core.internal.webkit.protocol.WebkitPage.java
/** * Convert base 64 data into a byte array. This method is provided for use with the * {@link #captureScreenshot(WebkitCallback)} method. * /*from w w w . j a v a 2 s .c om*/ * @param data base64 encoded data * @return */ public static byte[] convertBase64ToBinary(String data) { return DatatypeConverter.parseBase64Binary(data); }
From source file:com.vexsoftware.votifier.util.rsa.RSAIO.java
/** * Loads an RSA key pair from a directory. The directory must have the files * "public.key" and "private.key"./*www. ja v a 2 s . c o m*/ * * @param directory * The directory to load from * @return The key pair * @throws Exception * If an error occurs */ public static KeyPair load(File directory) throws Exception { // Read the public key file. File publicKeyFile = new File(directory + "/public.key"); FileInputStream in = null; byte[] encodedPublicKey; try { in = new FileInputStream(directory + "/public.key"); encodedPublicKey = new byte[(int) publicKeyFile.length()]; in.read(encodedPublicKey); encodedPublicKey = DatatypeConverter.parseBase64Binary(new String(encodedPublicKey)); } finally { try { in.close(); } catch (Exception exception) { // ignore } } // Read the private key file. File privateKeyFile = new File(directory + "/private.key"); byte[] encodedPrivateKey; try { in = new FileInputStream(directory + "/private.key"); encodedPrivateKey = new byte[(int) privateKeyFile.length()]; in.read(encodedPrivateKey); encodedPrivateKey = DatatypeConverter.parseBase64Binary(new String(encodedPrivateKey)); } finally { try { in.close(); } catch (Exception exception) { // ignore } } // Instantiate and return the key pair. KeyFactory keyFactory = KeyFactory.getInstance("RSA"); X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(encodedPublicKey); PublicKey publicKey = keyFactory.generatePublic(publicKeySpec); PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedPrivateKey); PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec); return new KeyPair(publicKey, privateKey); }
From source file:com.github.stephanarts.cas.ticket.registry.provider.UpdateMethod.java
/** * Execute the JSONRPCFunction.//from w ww . jav a 2 s . c o m * * @param params JSONRPC Method Parameters. * * @return JSONRPC result object * * @throws JSONRPCException implementors can throw JSONRPCExceptions containing the error. */ public JSONObject execute(final JSONObject params) throws JSONRPCException { JSONObject result = new JSONObject(); Ticket ticket; String ticketId = null; String serializedTicket = null; logger.debug("Update Ticket {}", ticketId); if (params.length() != 2) { throw new JSONRPCException(-32602, "Invalid Params"); } if (!(params.has("ticket-id") && params.has("ticket"))) { throw new JSONRPCException(-32602, "Invalid Params"); } try { ticketId = params.getString("ticket-id"); serializedTicket = params.getString("ticket"); ByteArrayInputStream bi = new ByteArrayInputStream( DatatypeConverter.parseBase64Binary(serializedTicket)); ObjectInputStream si = new ObjectInputStream(bi); ticket = (Ticket) si.readObject(); if (ticket.isExpired()) { logger.info("Ticket Expired {}", ticketId); } if (!this.map.containsKey(ticket.hashCode())) { logger.warn("Missing Key {}", ticketId); } this.map.put(ticketId.hashCode(), ticket); } catch (final Exception e) { throw new JSONRPCException(-32501, "Could not decode Ticket"); } logger.debug("Ticket-ID '{}'", ticketId); return result; }
From source file:com.github.stephanarts.cas.ticket.registry.provider.AddMethod.java
/** * Execute the JSONRPCFunction./*from www .ja va 2 s.co m*/ * * @param params JSONRPC Method Parameters. * * @return JSONRPC result object * * @throws JSONRPCException implementors can throw JSONRPCExceptions containing the error. */ public JSONObject execute(final JSONObject params) throws JSONRPCException { JSONObject result = new JSONObject(); String ticketId = null; String serializedTicket = null; Ticket ticket = null; logger.debug("Add Ticket"); if (params.length() != 2) { throw new JSONRPCException(-32602, "Invalid Params"); } if (!(params.has("ticket-id") && params.has("ticket"))) { throw new JSONRPCException(-32602, "Invalid Params"); } try { ticketId = params.getString("ticket-id"); serializedTicket = params.getString("ticket"); ByteArrayInputStream bi = new ByteArrayInputStream( DatatypeConverter.parseBase64Binary(serializedTicket)); ObjectInputStream si = new ObjectInputStream(bi); ticket = (Ticket) si.readObject(); } catch (final Exception e) { throw new JSONRPCException(-32501, "Could not decode Ticket"); } if (this.map.containsKey(ticketId.hashCode())) { logger.error("Duplicate Key {}", ticketId); throw new JSONRPCException(-32502, "Duplicate Ticket"); } else { this.map.put(ticketId.hashCode(), ticket); } logger.debug("Ticket-ID '{}'", ticketId); return result; }
From source file:fr.inria.oak.paxquery.pact.operators.unary.NestedAggregationOperator.java
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); String aggregationPathEncoded = parameters .getString(PACTOperatorsConfiguration.AGGREGATION_PATH_BINARY.toString(), null); byte[] aggregationPathBytes = DatatypeConverter.parseBase64Binary(aggregationPathEncoded); final int[] aggregationPath = (int[]) SerializationUtils.deserialize(aggregationPathBytes); this.aggregationPath = aggregationPath; String aggregationTypeEncoded = parameters .getString(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(), null); byte[] aggregationTypeBytes = DatatypeConverter.parseBase64Binary(aggregationTypeEncoded); final AggregationType aggregationType = (AggregationType) SerializationUtils .deserialize(aggregationTypeBytes); this.aggregationType = aggregationType; this.attachDummyColumn = parameters .getBoolean(PACTOperatorsConfiguration.ATTACH_DUMMY_COLUMN_BOOLEAN.toString(), false); }