mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-25 17:07:26 -04:00
Refactor various components
This commit is contained in:
@@ -11,12 +11,12 @@ public abstract class TupleNode extends DataStructureNode {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static TupleNode of(List<DataStructureNode> nodes) {
|
||||
public static TupleNode of(List<? extends DataStructureNode> nodes) {
|
||||
if (nodes == null) {
|
||||
throw new IllegalArgumentException("Nodes must be not null");
|
||||
}
|
||||
|
||||
return new NoKeyTupleNode(true, nodes);
|
||||
return new NoKeyTupleNode(true, (List<DataStructureNode>) nodes);
|
||||
}
|
||||
|
||||
public static TupleNode of(List<String> names, List<DataStructureNode> nodes) {
|
||||
|
||||
@@ -3,6 +3,4 @@ package io.xpipe.core.source;
|
||||
public interface DataSourceConnection extends AutoCloseable {
|
||||
|
||||
void init() throws Exception;
|
||||
|
||||
void close() throws Exception;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import java.io.OutputStream;
|
||||
|
||||
public interface TableDataReadConnection extends DataSourceConnection {
|
||||
|
||||
TupleType determineDataType() throws Exception;
|
||||
TupleType getDataType() throws Exception;
|
||||
|
||||
int determineRowCount() throws Exception;
|
||||
int getRowCount() throws Exception;
|
||||
|
||||
void withLines(DataStructureNodeAcceptor<TupleNode> lineAcceptor) throws Exception;
|
||||
|
||||
|
||||
@@ -4,9 +4,21 @@ import io.xpipe.core.store.DataStore;
|
||||
|
||||
public abstract class TableDataSourceDescriptor<DS extends DataStore> implements DataSourceDescriptor<DS> {
|
||||
|
||||
public abstract TableDataWriteConnection newWriteConnection(DS store);
|
||||
public final TableDataReadConnection openReadConnection(DS store) throws Exception {
|
||||
var con = newReadConnection(store);
|
||||
con.init();
|
||||
return con;
|
||||
}
|
||||
|
||||
public abstract TableDataReadConnection newReadConnection(DS store);
|
||||
public final TableDataWriteConnection openWriteConnection(DS store) throws Exception {
|
||||
var con = newWriteConnection(store);
|
||||
con.init();
|
||||
return con;
|
||||
}
|
||||
|
||||
protected abstract TableDataWriteConnection newWriteConnection(DS store);
|
||||
|
||||
protected abstract TableDataReadConnection newReadConnection(DS store);
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public abstract class InputStreamDataStore implements StreamDataStore {
|
||||
public class InputStreamDataStore implements StreamDataStore {
|
||||
|
||||
private final InputStream in;
|
||||
private BufferedInputStream bufferedInputStream;
|
||||
private boolean opened = false;
|
||||
|
||||
public InputStreamDataStore(InputStream in) {
|
||||
this.in = in;
|
||||
@@ -13,11 +16,17 @@ public abstract class InputStreamDataStore implements StreamDataStore {
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
return in;
|
||||
if (opened) {
|
||||
return bufferedInputStream;
|
||||
}
|
||||
|
||||
opened = true;
|
||||
bufferedInputStream = new BufferedInputStream(in);
|
||||
return bufferedInputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream openOutput() throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
throw new UnsupportedOperationException("No output available");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -65,7 +66,7 @@ public class LocalFileDataStore extends FileDataStore {
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
return Files.newInputStream(file);
|
||||
return new BufferedInputStream(Files.newInputStream(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user