Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public class DirectoryCacheStore implements ICacheStore<Path> {
@Override
public Path load(Path path) {
if (!path.isAbsolute()) throw new IllegalArgumentException();
if (!Files.isDirectory(path)) throw new IllegalArgumentException();
if (!path.isAbsolute()) throw new IllegalArgumentException(path + " is not absolute!");
if (!Files.isDirectory(path)) throw new IllegalArgumentException(path + " is not directory!");
return path;
}

Expand All @@ -38,7 +38,7 @@ public Path store(Path path, Path value) {
}
}
} catch (IOException exception) {
throw new RuntimeIOException(exception);
throw new RuntimeIOException("Failed to store " + value + " to " + path, exception);
}
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public Path load(Path path) {

@Override
public Path store(Path path, Path value) {
if (!path.isAbsolute()) throw new IllegalArgumentException();
if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path));
try {
Files.createDirectories(path.getParent());
Files.move(value, path, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException exception) {
throw new RuntimeIOException(exception);
throw new RuntimeIOException("Failed to store " + value + " to " + path, exception);
}
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
/**
* A cache store for objects, which uses a jackson object mapper to serialize and deserialize them.
*
* @param <T>
* The type of the values being stored.
* @param <T> The type of the values being stored.
*/
@Getter
@RequiredArgsConstructor
Expand All @@ -28,22 +27,22 @@ public class JacksonCacheStore<T> implements ICacheStore<T> {

@Override
public T load(Path path) {
if (!path.isAbsolute()) throw new IllegalArgumentException();
if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path));
try {
return getMapper().readValue(path.toFile(), type.getErasedType());
} catch (IOException e) {
throw new RuntimeIOException(e);
throw new RuntimeIOException("Failed to load " + getType() + " from " + path, e);
}
}

@Override
public T store(Path path, T value) {
if (!path.isAbsolute()) throw new IllegalArgumentException();
if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path));
try {
Files.createDirectories(path.getParent());
getMapper().writeValue(path.toFile(), value);
} catch (IOException e) {
throw new RuntimeIOException(e);
throw new RuntimeIOException("Failed to store " + value + " to " + path, e);
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ public class ObjectSerializationCacheStore<T> implements ICacheStore<T> {

@Override
public T load(Path path) {
if (!path.isAbsolute()) throw new IllegalArgumentException();
if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path));
try (ObjectInputStream objectInputStream = new ObjectInputStream(Files.newInputStream(path))) {
return type.cast(objectInputStream.readObject());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
throw new RuntimeException("Failed to load " + getType() + " from " + path, e);
} catch (IOException e) {
throw new RuntimeIOException(e);
throw new RuntimeIOException("Failed to load " + getType() + " from " + path, e);
}
}

@Override
public T store(Path path, T value) {
if (!path.isAbsolute()) throw new IllegalArgumentException();
if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path));
try {
Files.createDirectories(path.getParent());
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(Files.newOutputStream(path))) {
objectOutputStream.writeObject(value);
objectOutputStream.flush();
}
} catch (IOException e) {
throw new RuntimeIOException(e);
throw new RuntimeIOException("Failed to store " + value + " to " + path, e);
}
return value;
}
Expand Down