MetadataBlob(String b64WritingKey, String b64mapkey, String b64blobdata) { this( Base64.getDecoder().decode(b64WritingKey), b64WritingKey, Base64.getDecoder().decode(b64mapkey), b64mapkey, Base64.getDecoder().decode(b64blobdata), b64blobdata); }
MetadataBlob(byte[] writingKey, byte[] mapkey, byte[] blobdata) { this( writingKey, new String(Base64.getEncoder().encode(writingKey)), mapkey, new String(Base64.getEncoder().encode(mapkey)), blobdata, blobdata == null ? null : new String(Base64.getEncoder().encode(blobdata))); }
/** * Convert an MVD to a string * * @param mvd the MVD to convert * @param rb database properties file * @param folderId id of the folder to contain it in * @throws Exception raised if an error occurred */ public static String externalise(MVD mvd) throws Exception { int size = mvd.dataSize(); byte[] data = new byte[size]; int nBytes = mvd.serialise(data); assert nBytes == size : "MVD shorter than predicted"; return Base64.encodeBytes(data, Base64.GZIP); }
/** * Save an MVD to a file * * @param mvd the MVD to save * @param dst the file to save it to * @param rb database properties file * @param folderId id of the folder to contain it in * @throws Exception raised if an error occurred */ public static void externalise(MVD mvd, File dst, int folderId, Properties rb) throws Exception { long start = System.nanoTime() / 1000; System.gc(); long startMem = Runtime.getRuntime().freeMemory(); int size = mvd.dataSize(); byte[] data = new byte[size]; int nBytes = mvd.serialise(data); assert nBytes == size : "MVD shorter than predicted"; String str = Base64.encodeBytes(data, Base64.GZIP); if (rb == null) writeToFile(dst, str); else writeToDatabase(dst.getName(), str, mvd.description, folderId, rb); long end = System.nanoTime() / 1000; long endMem = Runtime.getRuntime().freeMemory(); System.out.println("internalise took " + (end - start) + " microseconds"); System.out.println("Memory used " + (startMem - endMem) + " bytes"); }
@Override public String getUsername(byte[] encodedKey) { String b64key = Base64.getEncoder().encodeToString(encodedKey); try { try (PreparedStatement preparedStatement = conn.prepareStatement("select name from users where publickey = ? limit 1")) { preparedStatement.setString(1, b64key); ResultSet resultSet = preparedStatement.executeQuery(); boolean next = resultSet.next(); if (!next) return ""; return resultSet.getString(1); } } catch (SQLException sqle) { throw new IllegalStateException(sqle); } }
/** * Decode the base-64 encoded text into a byte array, check the magic string at the start of the * file, and decompress it. * * @param base64Data the base64 data to decode * @return the byte array containing the decoded data. * @throws an exception if it is not an MVD file */ private static byte[] base64Decode(String base64Data) throws Exception { byte[] data = Base64.decode(base64Data); if (!magicOK(data)) throw new MVDException("Not a valid MVD file"); return data; }
RowData(String name, String d) { this(name, Base64.getDecoder().decode(d), d); }
RowData(String name, byte[] data) { this(name, data, (data == null ? null : new String(Base64.getEncoder().encode(data)))); }
StaticData(byte[] publicKey, byte[] staticdata) { super(new String(Base64.getEncoder().encode(publicKey)), staticdata); }