Search in sources :

Example 1 with AccessibleByteArrayOutputStream

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AccessibleByteArrayOutputStream(org.teiid.core.util.AccessibleByteArrayOutputStream) List(java.util.List) ArrayList(java.util.ArrayList) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with AccessibleByteArrayOutputStream

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);
            }
        }
    }
}
Also used : AccessibleByteArrayOutputStream(org.teiid.core.util.AccessibleByteArrayOutputStream) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) WrappedConnection(org.teiid.resource.spi.WrappedConnection) ObjectOutputStream(java.io.ObjectOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FunctionMethod(org.teiid.metadata.FunctionMethod) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with AccessibleByteArrayOutputStream

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()));
    }
}
Also used : AccessibleByteArrayOutputStream(org.teiid.core.util.AccessibleByteArrayOutputStream) SealedObject(javax.crypto.SealedObject) ObjectOutputStream(java.io.ObjectOutputStream) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

ObjectOutputStream (java.io.ObjectOutputStream)3 AccessibleByteArrayOutputStream (org.teiid.core.util.AccessibleByteArrayOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 IOException (java.io.IOException)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 SealedObject (javax.crypto.SealedObject)1 ResourceException (javax.resource.ResourceException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 FunctionMethod (org.teiid.metadata.FunctionMethod)1 WrappedConnection (org.teiid.resource.spi.WrappedConnection)1 TranslatorException (org.teiid.translator.TranslatorException)1