/** * @return decoded flags */ protected static boolean[] decodeBooleans(String flags) { // return null of there were no flags if (flags == null) return null; byte[] bytes = Base64.decodeBase64(flags.getBytes(UTF_8)); boolean[] bFlags = new boolean[bytes.length]; for (int i = 0; i < bytes.length; i++) { if (bytes[i] == 1) bFlags[i] = true; else bFlags[i] = false; } return bFlags; }
public static byte[] decodeBase64FileName(String node) { while (node.length() % 4 != 0) node += "="; /* decode transparently handles URLSafe encodings */ return Base64.decodeBase64(node.getBytes(UTF_8)); }
protected static Text[] decodeColumns(String columns) { String[] columnStrings = columns.split("\n"); Text[] columnTexts = new Text[columnStrings.length]; for (int i = 0; i < columnStrings.length; i++) { columnTexts[i] = new Text(Base64.decodeBase64(columnStrings[i].getBytes(UTF_8))); } return columnTexts; }
@Override public Set<String> listUsers() throws AccumuloSecurityException { Set<String> base64Users = zkAuthenticator.listUsers(); Set<String> readableUsers = new HashSet<>(); for (String base64User : base64Users) { readableUsers.add(new String(Base64.decodeBase64(base64User), UTF_8)); } return readableUsers; }
private static <T extends Writable> T fromBase64(T writable, String enc) { ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(enc)); DataInputStream dis = new DataInputStream(bais); try { writable.readFields(dis); } catch (IOException e) { throw new RuntimeException(e); } return writable; }
public static Set<Pair<Text,Text>> deserializeFetchedColumns(Collection<String> serialized) { Set<Pair<Text,Text>> columns = new HashSet<>(); if (null == serialized) { return columns; } for (String col : serialized) { int idx = col.indexOf(":"); Text cf = new Text(idx < 0 ? Base64.decodeBase64(col.getBytes(UTF_8)) : Base64.decodeBase64(col.substring(0, idx).getBytes(UTF_8))); Text cq = idx < 0 ? null : new Text(Base64.decodeBase64(col.substring(idx + 1).getBytes(UTF_8))); columns.add(new Pair<>(cf, cq)); } return columns; }
/** * Converts the serialized form to an instance of {@link Credentials}. The original serialized * form will not be affected. * * @param serializedForm * serialized form of credentials * @return deserialized credentials */ public static final Credentials deserialize(String serializedForm) { String[] split = serializedForm.split(":", 3); String principal = split[0].equals("-") ? null : new String(Base64.decodeBase64(split[0]), UTF_8); String tokenType = split[1].equals("-") ? null : new String(Base64.decodeBase64(split[1]), UTF_8); AuthenticationToken token = null; if (!split[2].equals("-")) { byte[] tokenBytes = Base64.decodeBase64(split[2]); token = AuthenticationTokenSerializer.deserialize(tokenType, tokenBytes); } return new Credentials(principal, token); }
line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.decodeBase64(line.getBytes(UTF_8))) : new Text(line));
private synchronized Text[] getCutPoints() throws IOException { if (cutPointArray == null) { String cutFileName = conf.get(CUTFILE_KEY); Path[] cf = DistributedCacheHelper.getLocalCacheFiles(conf); if (cf != null) { for (Path path : cf) { if (path.toUri().getPath() .endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) { TreeSet<Text> cutPoints = new TreeSet<>(); Scanner in = new Scanner(new BufferedReader( new InputStreamReader(new FileInputStream(path.toString()), UTF_8))); try { while (in.hasNextLine()) cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes(UTF_8)))); } finally { in.close(); } cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]); break; } } } if (cutPointArray == null) throw new FileNotFoundException(cutFileName + " not found in distributed cache"); } return cutPointArray; }
private synchronized Text[] getCutPoints() throws IOException { if (null == cutPointArray) { final String cutFileName = conf.get(CUTFILE_KEY); final Path[] cf = DistributedCacheHelper.getLocalCacheFiles(conf); if (null != cf) { for (final Path path : cf) { if (path.toUri().getPath().endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) { final TreeSet<Text> cutPoints = new TreeSet<>(); try (final Scanner in = openCutPointsStream(path)) { while (in.hasNextLine()) { cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes(UTF_8)))); } } cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]); break; } } } if (null == cutPointArray) { throw new FileNotFoundException(cutFileName + " not found in distributed cache"); } } return cutPointArray; }
/** * Constructs an authorizations object from a serialized form. This is NOT a constructor for a set * of authorizations of size one. Warning: This method does not verify that the encoded serialized * form is valid UTF-8. * * @param authorizations * a serialized authorizations string produced by {@link #getAuthorizationsArray()} or * {@link #serialize()}, converted to UTF-8 bytes * @throws IllegalArgumentException * if authorizations is null */ public Authorizations(byte[] authorizations) { checkArgument(authorizations != null, "authorizations is null"); String authsString = new String(authorizations, UTF_8); if (authsString.startsWith(HEADER)) { // it's the new format authsString = authsString.substring(HEADER.length()); if (authsString.length() > 0) { for (String encAuth : authsString.split(",")) { byte[] auth = Base64.decodeBase64(encAuth.getBytes(UTF_8)); auths.add(new ArrayByteSequence(auth)); } checkAuths(); } } else { // it's the old format if (authorizations.length > 0) setAuthorizations(authsString.split(",")); } }
String itstring = tokens.nextToken(); ByteArrayInputStream bais = new ByteArrayInputStream( Base64.decodeBase64(itstring.getBytes(UTF_8))); list.add(new IteratorSetting(new DataInputStream(bais))); bais.close();
private void create(String path, String value, String encoding) { byte[] data = value.getBytes(UTF_8); if ("base64".equals(encoding)) data = Base64.decodeBase64(data); try { try { zk.putPersistentData(path, data, overwrite ? NodeExistsPolicy.OVERWRITE : NodeExistsPolicy.FAIL); } catch (KeeperException e) { if (e.code().equals(KeeperException.Code.NODEEXISTS)) throw new RuntimeException(path + " exists. Remove it first."); throw e; } } catch (Exception e) { throw new RuntimeException(e); } } }
private Set<KeyExtent> parseMigrations(String migrations) { if (migrations == null) return Collections.emptySet(); try { Set<KeyExtent> result = new HashSet<>(); DataInputBuffer buffer = new DataInputBuffer(); byte[] data = Base64.decodeBase64(migrations.getBytes(UTF_8)); buffer.reset(data, data.length); while (buffer.available() > 0) { KeyExtent extent = new KeyExtent(); extent.readFields(buffer); result.add(extent); } return result; } catch (Exception ex) { throw new RuntimeException(ex); } }
/** * Gets the ranges to scan over from a job. * * @param implementingClass * the class whose name will be used as a prefix for the property configuration key * @param conf * the Hadoop configuration object to configure * @return the ranges * @throws IOException * if the ranges have been encoded improperly * @since 1.6.0 * @see #setRanges(Class, Configuration, Collection) */ public static List<Range> getRanges(Class<?> implementingClass, Configuration conf) throws IOException { Collection<String> encodedRanges = conf .getStringCollection(enumToConfKey(implementingClass, ScanOpts.RANGES)); List<Range> ranges = new ArrayList<>(); for (String rangeString : encodedRanges) { ByteArrayInputStream bais = new ByteArrayInputStream( Base64.decodeBase64(rangeString.getBytes(UTF_8))); Range range = new Range(); range.readFields(new DataInputStream(bais)); ranges.add(range); } return ranges; }
if (configString != null) { try { byte[] bytes = Base64.decodeBase64(configString.getBytes(UTF_8)); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); mapWritable.readFields(new DataInputStream(bais));
String tokenClass = in.readUTF(); byte[] base64TokenBytes = in.readUTF().getBytes(UTF_8); byte[] tokenBytes = Base64.decodeBase64(base64TokenBytes);
if (args.length == 2) return AuthenticationTokenSerializer.deserialize(args[0], Base64.decodeBase64(args[1].getBytes(UTF_8))); } else if (token.startsWith(TokenSource.FILE.prefix())) { String tokenFileName = token.substring(TokenSource.FILE.prefix().length());
private Map<String,MergeInfo> parseMerges(String merges) { if (merges == null) return null; try { Map<String,MergeInfo> result = new HashMap<>(); DataInputBuffer buffer = new DataInputBuffer(); byte[] data = Base64.decodeBase64(merges.getBytes(UTF_8)); buffer.reset(data, data.length); while (buffer.available() > 0) { MergeInfo mergeInfo = new MergeInfo(); mergeInfo.readFields(buffer); result.put(mergeInfo.extent.getTableId(), mergeInfo); } return result; } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { if (rand.nextInt(10) == 0) { shellState.getReader().beep(); shellState.getReader().println(); shellState.getReader() .println(new String(Base64 .decodeBase64(("ICAgICAgIC4tLS4KICAgICAgLyAvXCBcCiAgICAgKCAvLS1cICkKICAgICAuPl8gIF88" + "LgogICAgLyB8ICd8ICcgXAogICAvICB8Xy58Xy4gIFwKICAvIC98ICAgICAgfFwgXAog" + "fCB8IHwgfFwvfCB8IHwgfAogfF98IHwgfCAgfCB8IHxffAogICAgIC8gIF9fICBcCiAg" + "ICAvICAvICBcICBcCiAgIC8gIC8gICAgXCAgXF8KIHwvICAvICAgICAgXCB8IHwKIHxf" + "Xy8gICAgICAgIFx8X3wK").getBytes(UTF_8)), UTF_8)); } else { throw new ShellCommandException(ErrorCode.UNRECOGNIZED_COMMAND, getName()); } return 0; }