mirror of
https://github.com/apple/pkl.git
synced 2026-04-23 00:38:37 +02:00
Convert org.pkl.core.resource POJOs to record classes (#748)
This commit is contained in:
@@ -20,22 +20,19 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
/** An external (file, HTTP, etc.) resource. */
|
||||
public final class Resource {
|
||||
private final URI uri;
|
||||
|
||||
private final byte[] bytes;
|
||||
|
||||
/** Constructs a resource. */
|
||||
public Resource(URI uri, byte[] bytes) {
|
||||
this.uri = uri;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
/** Returns the URI of this resource. */
|
||||
public record Resource(URI uri, byte[] bytes) {
|
||||
/**
|
||||
* @deprecated As of 0.28.0, replaced by {@link #uri()}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public URI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of 0.28.0, replaced by {@link #bytes()}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public final class ResourceManager {
|
||||
|
||||
resourceFactory =
|
||||
new VmObjectFactory<Resource>(BaseModule::getResourceClass)
|
||||
.addProperty("uri", resource -> resource.getUri().toString())
|
||||
.addProperty("uri", resource -> resource.uri().toString())
|
||||
.addProperty("text", Resource::getText)
|
||||
.addProperty("base64", Resource::getBase64);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public final class ResourceNodes {
|
||||
@Specialization(guards = "self.hasExtraStorage()")
|
||||
protected String evalWithExtraStorage(VmTyped self) {
|
||||
var resource = (Resource) self.getExtraStorage();
|
||||
return ByteArrayUtils.md5(resource.getBytes());
|
||||
return ByteArrayUtils.md5(resource.bytes());
|
||||
}
|
||||
|
||||
@TruffleBoundary
|
||||
@@ -54,7 +54,7 @@ public final class ResourceNodes {
|
||||
@Specialization(guards = "self.hasExtraStorage()")
|
||||
protected String evalWithExtraStorage(VmTyped self) {
|
||||
var resource = (Resource) self.getExtraStorage();
|
||||
return ByteArrayUtils.sha1(resource.getBytes());
|
||||
return ByteArrayUtils.sha1(resource.bytes());
|
||||
}
|
||||
|
||||
@TruffleBoundary
|
||||
@@ -71,7 +71,7 @@ public final class ResourceNodes {
|
||||
@Specialization(guards = "self.hasExtraStorage()")
|
||||
protected String evalWithExtraStorage(VmTyped self) {
|
||||
var resource = (Resource) self.getExtraStorage();
|
||||
return ByteArrayUtils.sha256(resource.getBytes());
|
||||
return ByteArrayUtils.sha256(resource.bytes());
|
||||
}
|
||||
|
||||
@TruffleBoundary
|
||||
@@ -88,7 +88,7 @@ public final class ResourceNodes {
|
||||
@Specialization(guards = "self.hasExtraStorage()")
|
||||
protected long evalWithExtraStorage(VmTyped self) {
|
||||
var resource = (Resource) self.getExtraStorage();
|
||||
return ByteArrayUtils.sha256Int(resource.getBytes());
|
||||
return ByteArrayUtils.sha256Int(resource.bytes());
|
||||
}
|
||||
|
||||
@TruffleBoundary
|
||||
|
||||
Reference in New Issue
Block a user