use of org.teiid.core.util.AccessibleByteArrayOutputStream in project teiid by teiid.
the class TestEnginePerformance method writeReadBatch.
private List<List<Object>> writeReadBatch(String[] types, List<List<?>> batch) throws IOException, ClassNotFoundException {
AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream(5000);
ObjectOutputStream out = new ObjectOutputStream(baos);
BatchSerializer.writeBatch(out, types, batch);
out.flush();
byte[] bytes = baos.getBuffer();
ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes, 0, baos.getCount());
ObjectInputStream in = new ObjectInputStream(bytesIn);
List<List<Object>> newBatch = BatchSerializer.readBatch(in, types);
out.close();
in.close();
assertEquals(batch.size(), newBatch.size());
return newBatch;
}
use of org.teiid.core.util.AccessibleByteArrayOutputStream in project teiid by teiid.
the class NativeMetadataRepository method getMetadata.
private void getMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory) throws TranslatorException {
Object connection = null;
try {
connection = executionFactory.getConnection(connectionFactory, null);
} catch (Throwable e) {
// if security pass through is enabled the connection creation may fail at the startup
if (executionFactory.isSourceRequiredForMetadata()) {
throw new TranslatorException(QueryPlugin.Event.TEIID31178, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31178, factory.getName()));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception getting connection for metadata, but no connection is required");
}
Object unwrapped = null;
if (connection instanceof WrappedConnection) {
try {
unwrapped = ((WrappedConnection) connection).unwrap();
} catch (ResourceException e) {
if (executionFactory.isSourceRequiredForMetadata()) {
throw new TranslatorException(QueryPlugin.Event.TEIID30477, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, factory.getName()));
}
connection = null;
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Could not unwrap exception to get metadata, but no connection is required");
}
}
try {
executionFactory.getMetadata(factory, (unwrapped == null) ? connection : unwrapped);
} finally {
executionFactory.closeConnection(connection, connectionFactory);
}
if (PropertiesUtils.getBooleanProperty(factory.getModelProperties(), IMPORT_PUSHDOWN_FUNCTIONS, false)) {
// $NON-NLS-1$
List<FunctionMethod> functions = executionFactory.getPushDownFunctions();
// create a copy and add to the schema
if (!functions.isEmpty()) {
try {
AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(functions);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.getBuffer(), 0, baos.getCount()));
functions = (List<FunctionMethod>) ois.readObject();
for (FunctionMethod functionMethod : functions) {
factory.addFunction(functionMethod);
functionMethod.setProperty(FunctionMethod.SYSTEM_NAME, functionMethod.getName());
}
} catch (IOException e) {
throw new TeiidRuntimeException(e);
} catch (ClassNotFoundException e) {
throw new TeiidRuntimeException(e);
}
}
}
}
use of org.teiid.core.util.AccessibleByteArrayOutputStream in project teiid by teiid.
the class BasicCryptor method sealObject.
public synchronized Object sealObject(Object object) throws CryptoException {
try {
if (useSealedObject) {
return new SealedObject((Serializable) object, encryptCipher);
}
AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream(1 << 13);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
oos.flush();
oos.close();
return encrypt(baos.getBuffer(), 0, baos.getCount());
} catch (Exception e) {
try {
initEncryptCipher();
} catch (CryptoException err) {
// shouldn't happen
}
throw new CryptoException(CorePlugin.Event.TEIID10013, CorePlugin.Util.gs(CorePlugin.Event.TEIID10013, e.getMessage()));
}
}
Aggregations