import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
try {
Files.move(temp.toPath(), actual.toPath(), StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
- LOG.warn("Failed to move %s to %s. Deleting %s..", temp, actual, temp, e);
+ LOG.warn("Failed to move {} to {}. Deleting {}..", temp, actual, temp, e);
if (!temp.delete()) {
LOG.error("Failed to successfully delete file {}", temp);
}
}
try {
- String persistenceId = name.substring(PERSISTENCE_ID_START_INDEX, persistenceIdEndIndex);
+ // Since the persistenceId is url encoded in the filename, we need
+ // to decode relevant filename's part to obtain persistenceId back
+ String persistenceId = decode(name.substring(PERSISTENCE_ID_START_INDEX, persistenceIdEndIndex));
long sequenceNumber = Long.parseLong(name.substring(persistenceIdEndIndex + 1, sequenceNumberEndIndex));
long timestamp = Long.parseLong(name.substring(sequenceNumberEndIndex + 1));
return new SnapshotMetadata(persistenceId, sequenceNumber, timestamp);
}
}
+ private static String decode(final String str) {
+ try {
+ return URLDecoder.decode(str, StandardCharsets.UTF_8.name());
+ } catch (final UnsupportedEncodingException e) {
+ // Shouldn't happen
+ LOG.warn("Error decoding {}", str, e);
+ return str;
+ }
+ }
+
@VisibleForTesting
static int compare(final SnapshotMetadata m1, final SnapshotMetadata m2) {
return (int) (!m1.persistenceId().equals(m2.persistenceId())