Search in sources :

Example 86 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project voltdb by VoltDB.

the class NonVoltDBBackend method runSQLWithSubstitutions.

VoltTable runSQLWithSubstitutions(final SQLStmt stmt, ParameterSet params, byte[] paramJavaTypes) {
    //HSQLProcedureWrapper does nothing smart. it just implements this interface with runStatement()
    StringBuilder sqlOut = new StringBuilder(stmt.getText().length() * 2);
    assert (paramJavaTypes != null);
    int lastIndex = 0;
    String sql = stmt.getText();
    // if there's no ? in the statmemt, then zero out any auto-parameterization
    int paramCount = StringUtils.countMatches(sql, "?");
    if (paramCount == 0) {
        params = ParameterSet.emptyParameterSet();
        paramJavaTypes = new byte[0];
    }
    Object[] paramObjs = params.toArray();
    for (int i = 0; i < paramObjs.length; i++) {
        int nextIndex = sql.indexOf('?', lastIndex);
        if (nextIndex == -1)
            throw new RuntimeException("SQL Statement has more arguments than params.");
        sqlOut.append(sql, lastIndex, nextIndex);
        lastIndex = nextIndex + 1;
        VoltType type = VoltType.get(paramJavaTypes[i]);
        if (VoltType.isVoltNullValue(paramObjs[i])) {
            sqlOut.append("NULL");
        } else if (paramObjs[i] instanceof TimestampType) {
            if (type != VoltType.TIMESTAMP)
                throw new RuntimeException("Inserting date into mismatched column type in HSQL.");
            TimestampType d = (TimestampType) paramObjs[i];
            // convert VoltDB's microsecond granularity to millis.
            Timestamp t = new Timestamp(d.getTime() / 1000);
            sqlOut.append('\'').append(t.toString()).append('\'');
        } else if (paramObjs[i] instanceof byte[]) {
            if (type == VoltType.STRING) {
                // Convert from byte[] -> String; escape single quotes
                try {
                    sqlOut.append(sqlEscape(new String((byte[]) paramObjs[i], "UTF-8")));
                } catch (UnsupportedEncodingException e) {
                    // should NEVER HAPPEN
                    System.err.println("FATAL: Your JVM doens't support UTF-8");
                    System.exit(-1);
                }
            } else if (type == VoltType.VARBINARY) {
                // Convert from byte[] -> String; using hex
                sqlOut.append(sqlEscape(Encoder.hexEncode((byte[]) paramObjs[i])));
            } else {
                throw new RuntimeException("Inserting string/varbinary (bytes) into mismatched column type in HSQL.");
            }
        } else if (paramObjs[i] instanceof String) {
            if (type != VoltType.STRING)
                throw new RuntimeException("Inserting string into mismatched column type in HSQL.");
            // Escape single quotes
            sqlOut.append(sqlEscape((String) paramObjs[i]));
        } else {
            if (type == VoltType.TIMESTAMP) {
                long t = Long.parseLong(paramObjs[i].toString());
                TimestampType d = new TimestampType(t);
                // convert VoltDB's microsecond granularity to millis
                Timestamp ts = new Timestamp(d.getTime() * 1000);
                sqlOut.append('\'').append(ts.toString()).append('\'');
            } else
                sqlOut.append(paramObjs[i].toString());
        }
    }
    sqlOut.append(sql, lastIndex, sql.length());
    return runDML(sqlOut.toString());
}
Also used : TimestampType(org.voltdb.types.TimestampType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Timestamp(java.sql.Timestamp)

Example 87 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project voltdb by VoltDB.

the class paymentByCustomerNameW method run.

public VoltTable[] run(short w_id, byte d_id, double h_amount, short c_w_id, byte c_d_id, byte[] c_last, TimestampType timestamp) throws VoltAbortException {
    // retrieve c_id from replicated CUSTOMER_NAME table
    voltQueueSQL(getCidByLastName, c_last, c_d_id, c_w_id);
    final VoltTable result = voltExecuteSQL()[0];
    final int namecnt = result.getRowCount();
    if (namecnt == 0) {
        String c_lastString = null;
        try {
            c_lastString = new String(c_last, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        throw new VoltAbortException("paymentByCustomerNameW: no customers with last name: " + c_lastString + " in warehouse: " + c_w_id + " and in district " + c_d_id);
    }
    final int index = (namecnt - 1) / 2;
    final VoltTableRow customer = result.fetchRow(index);
    final long c_id = customer.getLong(0);
    return processPayment(w_id, d_id, h_amount, c_w_id, c_d_id, c_id, timestamp);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 88 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project voltdb by VoltDB.

the class TestCatalogUpdateSuite method negativeTests.

public void negativeTests(Client client) throws UnsupportedEncodingException {
    // this fails because the catalog URL isn't a real thing but needs to point at
    // a file that actually exists.  Point to the compiled java class for this suite
    URL url = TestCatalogUpdateSuite.class.getResource("TestCatalogUpdateSuite.class");
    String newCatalogURL = URLDecoder.decode(url.getPath(), "UTF-8");
    String deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-addtables.xml");
    try {
        client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
        fail();
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("Database catalog not found"));
    }
}
Also used : File(java.io.File) URL(java.net.URL) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 89 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project voltdb by VoltDB.

the class CatalogBuilder method addSchema.

/**
     * Add a schema based on a URL.
     * @param schemaURL Schema file URL
     */
public void addSchema(String schemaURL) {
    try {
        schemaURL = URLDecoder.decode(schemaURL, "UTF-8");
    } catch (final UnsupportedEncodingException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    assert (m_schemas.contains(schemaURL) == false);
    final File schemaFile = new File(schemaURL);
    assert (schemaFile != null);
    assert (schemaFile.isDirectory() == false);
    // this check below fails in some valid cases (like when the file is in a jar)
    //assert schemaFile.canRead()
    //    : "can't read file: " + schemaPath;
    m_schemas.add(schemaURL);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File)

Example 90 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project android_frameworks_base by ResurrectionRemix.

the class HdmiCecLocalDeviceTv method handleSetOsdName.

@Override
@ServiceThreadOnly
protected boolean handleSetOsdName(HdmiCecMessage message) {
    int source = message.getSource();
    HdmiDeviceInfo deviceInfo = getCecDeviceInfo(source);
    // If the device is not in device list, ignore it.
    if (deviceInfo == null) {
        Slog.e(TAG, "No source device info for <Set Osd Name>." + message);
        return true;
    }
    String osdName = null;
    try {
        osdName = new String(message.getParams(), "US-ASCII");
    } catch (UnsupportedEncodingException e) {
        Slog.e(TAG, "Invalid <Set Osd Name> request:" + message, e);
        return true;
    }
    if (deviceInfo.getDisplayName().equals(osdName)) {
        Slog.i(TAG, "Ignore incoming <Set Osd Name> having same osd name:" + message);
        return true;
    }
    addCecDevice(new HdmiDeviceInfo(deviceInfo.getLogicalAddress(), deviceInfo.getPhysicalAddress(), deviceInfo.getPortId(), deviceInfo.getDeviceType(), deviceInfo.getVendorId(), osdName));
    return true;
}
Also used : HdmiDeviceInfo(android.hardware.hdmi.HdmiDeviceInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceThreadOnly(com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)3108 IOException (java.io.IOException)878 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)284 InputStream (java.io.InputStream)275 ArrayList (java.util.ArrayList)268 InputStreamReader (java.io.InputStreamReader)243 File (java.io.File)234 ByteArrayInputStream (java.io.ByteArrayInputStream)209 ByteArrayOutputStream (java.io.ByteArrayOutputStream)201 FileNotFoundException (java.io.FileNotFoundException)198 HashMap (java.util.HashMap)182 MessageDigest (java.security.MessageDigest)180 BufferedReader (java.io.BufferedReader)150 URL (java.net.URL)150 Map (java.util.Map)148 OutputStreamWriter (java.io.OutputStreamWriter)145 FileOutputStream (java.io.FileOutputStream)120 MalformedURLException (java.net.MalformedURLException)110 FileInputStream (java.io.FileInputStream)107 List (java.util.List)105