mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-08-18 07:16:31 +00:00
Add dynamic tunnels
This commit is contained in:
@@ -9,13 +9,10 @@ import lombok.Getter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonTypeName("internalStream")
|
||||
@@ -35,20 +32,10 @@ public class InternalStreamStore extends JacksonizedValue implements StreamDataS
|
||||
return DataFlow.INPUT_OUTPUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> determineDefaultName() {
|
||||
return Optional.of(uuid.toString());
|
||||
}
|
||||
|
||||
private Path getFile() {
|
||||
return DataStateProvider.get().getInternalStreamStore(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Instant> determineLastModified() throws IOException {
|
||||
return Optional.of(Files.getLastModifiedTime(getFile()).toInstant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
return Files.newInputStream(getFile());
|
||||
|
||||
@@ -5,11 +5,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import io.xpipe.core.store.DataStore;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonTypeName("localDir")
|
||||
@EqualsAndHashCode
|
||||
@@ -22,21 +18,6 @@ public class LocalDirectoryDataStore implements DataStore {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> determineDefaultName() {
|
||||
return Optional.of(file.getFileName().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Instant> determineLastModified() {
|
||||
try {
|
||||
var l = Files.getLastModifiedTime(file);
|
||||
return Optional.of(l.toInstant());
|
||||
} catch (IOException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Path getPath() {
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,6 @@ import lombok.Getter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A store that refers to another store in the XPipe storage.
|
||||
* The referenced store has to be resolved by the caller manually, as this class does not act as a resolver.
|
||||
@@ -36,13 +33,4 @@ public final class NamedStore implements DataStore {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> determineDefaultName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Instant> determineLastModified() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,6 @@ import io.xpipe.core.impl.StdinDataStore;
|
||||
import io.xpipe.core.impl.StdoutDataStore;
|
||||
import io.xpipe.core.source.DataSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A data store represents some form of a location where data is stored, e.g. a file or a database.
|
||||
* It does not contain any information on what data is stored,
|
||||
@@ -77,6 +73,10 @@ public interface DataStore {
|
||||
*/
|
||||
default void validate() throws Exception {}
|
||||
|
||||
default void initializeValidate() throws Exception {}
|
||||
|
||||
default void finalizeValidate() throws Exception {}
|
||||
|
||||
default void checkComplete() throws Exception {}
|
||||
|
||||
default boolean delete() {
|
||||
@@ -90,19 +90,4 @@ public interface DataStore {
|
||||
default <DS extends DataStore> DS asNeeded() {
|
||||
return (DS) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines on optional default name for this data store that is
|
||||
* used when determining a suitable default name for a data source.
|
||||
*/
|
||||
default Optional<String> determineDefaultName() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the last modified of this data store if this data store supports it.
|
||||
*/
|
||||
default Optional<Instant> determineLastModified() throws IOException {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents a store that has a filename.
|
||||
* Note that this does not only apply to file stores but any other store as well that has some kind of file name.
|
||||
*/
|
||||
public interface FilenameStore extends DataStore {
|
||||
|
||||
@Override
|
||||
default Optional<String> determineDefaultName() {
|
||||
var n = getFileName();
|
||||
var i = n.lastIndexOf('.');
|
||||
return Optional.of(i != -1 ? n.substring(0, i) : n);
|
||||
}
|
||||
|
||||
default String getFileExtension() {
|
||||
var split = getFileName().split("[\\\\.]");
|
||||
if (split.length == 0) {
|
||||
|
||||
@@ -6,6 +6,10 @@ import java.util.function.Supplier;
|
||||
|
||||
public interface StatefulDataStore extends DataStore {
|
||||
|
||||
default boolean isInStorage() {
|
||||
return DataStateProvider.get().isInStorage(this);
|
||||
}
|
||||
|
||||
default <T> T getState(String key, Class<T> c, T def) {
|
||||
return DataStateProvider.get().getState(this, key, c, () -> def);
|
||||
}
|
||||
|
||||
@@ -25,5 +25,7 @@ public abstract class DataStateProvider {
|
||||
|
||||
public abstract <T> T getState(DataStore store, String key, Class<T> c, Supplier<T> def);
|
||||
|
||||
public abstract boolean isInStorage(DataStore store);
|
||||
|
||||
public abstract Path getInternalStreamStore(UUID id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user