use of org.teiid.common.buffer.FileStore in project teiid by teiid.
the class TextAgg method buildResult.
private FileStoreInputStreamFactory buildResult(CommandContext context) throws TeiidProcessingException {
try {
// $NON-NLS-1$
FileStore fs = context.getBufferManager().createFileStore("textagg");
FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, textLine.getEncoding() == null ? Streamable.ENCODING : textLine.getEncoding());
Writer w = fisf.getWriter();
if (textLine.isIncludeHeader()) {
Object[] header = TextLine.evaluate(textLine.getExpressions(), new TextLine.ValueExtractor<DerivedColumn>() {
public Object getValue(DerivedColumn t) {
if (t.getAlias() == null && t.getExpression() instanceof ElementSymbol) {
return ((ElementSymbol) t.getExpression()).getShortName();
}
return t.getAlias();
}
}, textLine);
writeList(w, header);
}
w.flush();
return fisf;
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30420, e);
}
}
use of org.teiid.common.buffer.FileStore in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method createLayeredCache.
private static BufferFrontedFileStoreCache createLayeredCache(int bufferSpace, int objectSize, boolean memStorage, boolean allocate) throws TeiidComponentException {
BufferFrontedFileStoreCache fsc = new BufferFrontedFileStoreCache();
// prevent asynch affects
fsc.cleanerRunning.set(true);
fsc.setMemoryBufferSpace(bufferSpace);
fsc.setMaxStorageObjectSize(objectSize);
fsc.setDirect(false);
if (memStorage) {
SplittableStorageManager ssm = new SplittableStorageManager(new MemoryStorageManager());
ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
fsc.setStorageManager(ssm);
} else {
StorageManager sm = new StorageManager() {
@Override
public void initialize() throws TeiidComponentException {
}
@Override
public FileStore createFileStore(String name) {
return new FileStore() {
@Override
public void setLength(long length) throws IOException {
throw new OutOfDiskException(null);
}
@Override
protected void removeDirect() {
}
@Override
protected int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException {
return 0;
}
@Override
public long getLength() {
return 0;
}
};
}
@Override
public long getMaxStorageSpace() {
return -1;
}
};
fsc.setStorageManager(sm);
}
fsc.initialize(allocate);
return fsc;
}
use of org.teiid.common.buffer.FileStore in project teiid by teiid.
the class TestBufferManagerImpl method testFileStoreMax.
@Test(expected = IOException.class)
public void testFileStoreMax() throws Exception {
BufferManagerImpl bufferManager = new BufferManagerImpl();
bufferManager.setCache(new MemoryStorageManager() {
@Override
public long getMaxStorageSpace() {
return 640;
}
});
bufferManager.setMaxActivePlans(20);
bufferManager.initialize();
FileStore fs = bufferManager.createFileStore("x");
fs.write(new byte[10], 0, 10);
}
use of org.teiid.common.buffer.FileStore in project teiid by teiid.
the class TestFileStorageManager method testWritingMultipleFiles.
@Test
public void testWritingMultipleFiles() throws Exception {
FileStorageManager sm = getStorageManager(null, null);
// $NON-NLS-1$
String tsID = "0";
// Add one batch
FileStore store = sm.createFileStore(tsID);
String contentOrig = new String("some file content this will stored in same tmp file with another");
OutputStream out = store.createOutputStream();
out.write(contentOrig.getBytes(), 0, contentOrig.getBytes().length);
out.close();
out = store.createOutputStream();
long start = store.getLength();
byte[] bytesOrig = new byte[2048];
r.nextBytes(bytesOrig);
out.write(bytesOrig, 0, 2048);
byte[] readContent = new byte[2048];
InputStream in = store.createInputStream(0, contentOrig.getBytes().length);
int c = in.read(readContent, 0, 3000);
assertEquals(contentOrig, new String(readContent, 0, c));
c = in.read(readContent, 0, 3000);
assertEquals(-1, c);
in.close();
in = store.createInputStream(start, 2048);
c = in.read(readContent, 0, 3000);
assertTrue(Arrays.equals(bytesOrig, readContent));
c = in.read(readContent, 0, 3000);
assertEquals(-1, c);
in.close();
}
use of org.teiid.common.buffer.FileStore in project teiid by teiid.
the class TestFileStorageManager method testInitialRead.
@Test
public void testInitialRead() throws Exception {
FileStorageManager sm = getStorageManager(null, null);
// $NON-NLS-1$
String tsID = "0";
FileStore store = sm.createFileStore(tsID);
assertEquals(-1, store.read(0, new byte[1], 0, 1));
}
Aggregations