List of usage examples for java.util Base64 getDecoder
public static Decoder getDecoder()
From source file:org.silverpeas.core.util.SerializationUtil.java
/** * <p>Deserializes a single {@code Object} from a string.</p> * @param <T> the type of the returned serializable object * @param objectStringData the serialized object, must not be null * @return the deserialized object/*from w ww .jav a 2s. c o m*/ * @throws IllegalArgumentException if {@code objectData} is {@code null} * @throws SerializationException (runtime) if the serialization fails */ @SuppressWarnings("unchecked") public static <T extends Serializable> T deserializeFromString(String objectStringData) { if (objectStringData == null) { throw new IllegalArgumentException("data must exist"); } return (T) SerializationUtils.deserialize(Base64.getDecoder().decode(objectStringData)); }
From source file:org.apache.accumulo.shell.ShellUtil.java
/** * Scans the given file line-by-line (ignoring empty lines) and returns a list containing those * lines. If decode is set to true, every line is decoded using {@link Base64} from the UTF-8 * bytes of that line before inserting in the list. * * @param filename/*from w ww . j a va 2s.co m*/ * Path to the file that needs to be scanned * @param decode * Whether to decode lines in the file * @return List of {@link Text} objects containing data in the given file * @throws FileNotFoundException * if the given file doesn't exist */ @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") public static List<Text> scanFile(String filename, boolean decode) throws FileNotFoundException { String line; List<Text> result = new ArrayList<>(); try (Scanner file = new Scanner(new File(filename), UTF_8.name())) { while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.getDecoder().decode(line)) : new Text(line)); } } } return result; }
From source file:io.kodokojo.endpoint.BasicAuthenticator.java
@Override public void handle(Request request, Response response) throws Exception { String authorization = request.headers("Authorization"); if (StringUtils.isNotBlank(authorization) && authorization.startsWith("Basic ")) { String encoded = authorization.substring("Basic ".length()); String decoded = new String(Base64.getDecoder().decode(encoded)); String[] split = decoded.split(":"); username = split[0];//from w w w . jav a 2s . c om password = split[1]; } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("Basic Authorization header not found."); if (LOGGER.isTraceEnabled()) { LOGGER.trace("List of Header of current request {}", StringUtils.join(request.headers(), ",")); LOGGER.trace("List of attribute : {}", StringUtils.join(request.attributes(), ",")); LOGGER.trace("List of params : {}", StringUtils.join(request.queryParams(), ",")); } } }
From source file:org.apache.james.util.SerializationUtil.java
/** * Decodes the input base64 string and deserialize it. * * @param <T> The resulting type after deserialization. * @param object The base64 encoded string. * * @return The deserialized object./*from w w w . j a va 2s . co m*/ */ public static <T extends Serializable> T deserialize(String object) { return Optional.ofNullable(object).map(Base64.getDecoder()::decode).<T>map(SerializationUtils::deserialize) .orElse(null); }
From source file:com.google.testing.web.screenshotter.Screenshot.java
/** * Returns the decoded bytes for the screenshot. Every call to this returns a new copy of the * decoded bytes.//from ww w . j a v a 2 s . c om */ public byte[] asBytes() { return Base64.getDecoder().decode(base64); }
From source file:za.co.bronkode.jwtbroker.Tokenizer.java
public static Token DecodeToken(String token) { if (IsValidToken(token)) { try {/*from w ww . j av a 2s. co m*/ String[] items = token.split("\\."); Token t = new Token(); ObjectMapper mapper = new ObjectMapper(); byte[] headerBytes = Base64.getDecoder().decode(items[0]); byte[] claimBytes = Base64.getDecoder().decode(items[1]); String headerjson = new String(headerBytes); String claimjson = new String(claimBytes); t.setHeader(mapper.readValue(headerjson, TokenHeader.class)); t.setClaim(mapper.readValue(claimjson, claimClass)); return t; } catch (IOException ex) { Logger.getLogger(Tokenizer.class.getName()).log(Level.SEVERE, null, ex); } } else { return null; } return null; }
From source file:org.trustedanalytics.servicebroker.gearpump.yarn.YarnConfigFilesProvider.java
private void decode() { decodedConfigFiles = Base64.getDecoder().decode(getConfigFiles()); }
From source file:de.kaiserpfalzEdv.commons.encoding.EncodingHelper.java
/** * Decodes the Object stream into an object. * * @param objectString the BASE64 encoded string containing a serialized object. * @return the object itself./*from ww w .ja va2 s . c om*/ * @throws EncodingException If an {@link IOException} or * {@link ClassNotFoundException} was thrown. */ public static Object decode(final String objectString) { LOG.trace("Trying to decode string: {}", objectString); checkArgument(isNotBlank(objectString), "Can't decode NULL or empty String!"); Object out = SerializationUtils.deserialize(Base64.getDecoder().decode(objectString)); LOG.debug("Decoded BASE64 encoded object from string. Now returning object."); return out; }
From source file:com.toptal.conf.SecurityUtils.java
/** * Decodes given string from base64.//w ww. j a v a2s .c om * @param str String. * @return Decoded string. */ public static String decode(final String str) { String result = null; if (str != null) { result = new String(Base64.getDecoder().decode(str), StandardCharsets.UTF_8); } return result; }
From source file:org.apache.accumulo.shell.commands.HiddenCommand.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { if (rand.nextInt(10) == 0) { shellState.getReader().beep();/*from ww w. j ava 2s . c o m*/ shellState.getReader().println(); shellState.getReader().println(new String(Base64.getDecoder().decode( "ICAgICAgIC4tLS4KICAgICAgLyAvXCBcCiAgICAgKCAvLS1cICkKICAgICAuPl8gIF88LgogICAgLyB8ICd8ICcgXAog" + "ICAvICB8Xy58Xy4gIFwKICAvIC98ICAgICAgfFwgXAogfCB8IHwgfFwvfCB8IHwgfAogfF98IHwgfCAgfCB8IHxffAogICAgIC8gIF9fICBcCiAgICAvICAv" + "ICBcICBcCiAgIC8gIC8gICAgXCAgXF8KIHwvICAvICAgICAgXCB8IHwKIHxfXy8gICAgICAgIFx8X3wK"), UTF_8)); } else { throw new ShellCommandException(ErrorCode.UNRECOGNIZED_COMMAND, getName()); } return 0; }