Search in sources :

Example 76 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project TotalFreedomMod by TotalFreedom.

the class Module_file method encodeUri.

private String encodeUri(String uri) {
    String newUri = "";
    StringTokenizer st = new StringTokenizer(uri, "/ ", true);
    while (st.hasMoreTokens()) {
        String tok = st.nextToken();
        if (tok.equals("/")) {
            newUri += "/";
        } else if (tok.equals(" ")) {
            newUri += "%20";
        } else {
            try {
                newUri += URLEncoder.encode(tok, "UTF-8");
            } catch (UnsupportedEncodingException ignored) {
            }
        }
    }
    return newUri;
}
Also used : StringTokenizer(java.util.StringTokenizer) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 77 with UnsupportedEncodingException

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

the class HTTPUtils method getHashedPasswordForHTTPVar.

public static String getHashedPasswordForHTTPVar(String password) {
    assert (password != null);
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    byte[] hashedPassword = null;
    try {
        hashedPassword = md.digest(password.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("JVM doesn't support UTF-8. Please use a supported JVM", e);
    }
    String retval = Encoder.hexEncode(hashedPassword);
    return retval;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 78 with UnsupportedEncodingException

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

the class HTTPUtils method getHashedPasswordForHTTPVar.

public static String getHashedPasswordForHTTPVar(String password) {
    assert (password != null);
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    byte[] hashedPassword = null;
    try {
        hashedPassword = md.digest(password.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("JVM doesn't support UTF-8. Please use a supported JVM", e);
    }
    String retval = Encoder.hexEncode(hashedPassword);
    return retval;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 79 with UnsupportedEncodingException

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

the class PassAllArgTypes method run.

public VoltTable[] run(byte b, byte[] bArray, short s, short[] sArray, int i, int[] iArray, long l, long[] lArray, String str, byte[] bString, TimestampType tst, java.util.Date utild, java.sql.Date sqld, java.sql.Timestamp ts) throws VoltAbortException {
    if (b != 100)
        throw new VoltAbortException();
    if (bArray[0] != 100 || bArray[1] != 101 || bArray[2] != 102)
        throw new VoltAbortException();
    if (s != 32000)
        throw new VoltAbortException();
    if (sArray[0] != 32000 || sArray[1] != 32001 || sArray[2] != 32002)
        throw new VoltAbortException();
    if (i != 2147483640)
        throw new VoltAbortException();
    if (iArray[0] != 2147483640 || iArray[1] != 2147483641 || iArray[2] != 2147483642)
        throw new VoltAbortException();
    if (l != Long.MAX_VALUE - 10)
        throw new VoltAbortException();
    if (lArray[0] != Long.MAX_VALUE - 10 || lArray[1] != Long.MAX_VALUE - 9 || lArray[2] != Long.MAX_VALUE - 8)
        throw new VoltAbortException();
    if (!str.equals("foo"))
        throw new VoltAbortException();
    try {
        if (!(new String(bString, "UTF-8").equals("bar")))
            throw new VoltAbortException();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (!tst.equals(new TimestampType(MILLISECONDS_SINCE_EPOCH_TEST_VALUE * 1000))) {
        throw new VoltAbortException();
    }
    if (!utild.equals(new java.util.Date(MILLISECONDS_SINCE_EPOCH_TEST_VALUE))) {
        throw new VoltAbortException();
    }
    if (!sqld.equals(new java.sql.Date(MILLISECONDS_SINCE_EPOCH_TEST_VALUE))) {
        throw new VoltAbortException();
    }
    if (!ts.equals(new java.sql.Timestamp(MILLISECONDS_SINCE_EPOCH_TEST_VALUE))) {
        throw new VoltAbortException();
    }
    VoltTable result0 = new VoltTable(new VoltTable.ColumnInfo("b", VoltType.typeFromClass(byte.class)), new VoltTable.ColumnInfo("bArray", VoltType.typeFromClass(byte[].class)), new VoltTable.ColumnInfo("s", VoltType.typeFromClass(short.class)), // new VoltTable.ColumnInfo("sArray", VoltType.typeFromClass(short[].class)),
    new VoltTable.ColumnInfo("i", VoltType.typeFromClass(int.class)), // new VoltTable.ColumnInfo("iArray", VoltType.typeFromClass(int[].class)),
    new VoltTable.ColumnInfo("l", VoltType.typeFromClass(long.class)), // new VoltTable.ColumnInfo("lArray", VoltType.typeFromClass(long[].class)),
    new VoltTable.ColumnInfo("str", VoltType.typeFromClass(String.class)), new VoltTable.ColumnInfo("bString", VoltType.typeFromClass(byte[].class)), new VoltTable.ColumnInfo("tst", VoltType.typeFromClass(TimestampType.class)), new VoltTable.ColumnInfo("utild", VoltType.typeFromClass(java.util.Date.class)), new VoltTable.ColumnInfo("sqld", VoltType.typeFromClass(java.sql.Date.class)), new VoltTable.ColumnInfo("ts", VoltType.typeFromClass(java.sql.Timestamp.class)));
    result0.addRow(b, bArray, s, /*sArray,*/
    i, /*iArray,*/
    l, /*lArray,*/
    str, bString, tst, utild, sqld, ts);
    VoltTable result1 = new VoltTable(new VoltTable.ColumnInfo("sArray", VoltType.typeFromClass(short.class)));
    for (int j = 0; j < sArray.length; j++) {
        result1.addRow(sArray[j]);
    }
    VoltTable result2 = new VoltTable(new VoltTable.ColumnInfo("iArray", VoltType.typeFromClass(int.class)));
    for (int j = 0; j < iArray.length; j++) {
        result2.addRow(iArray[j]);
    }
    VoltTable result3 = new VoltTable(new VoltTable.ColumnInfo("lArray", VoltType.typeFromClass(long.class)));
    for (int j = 0; j < lArray.length; j++) {
        result3.addRow(lArray[j]);
    }
    return new VoltTable[] { result0, result1, result2, result3 };
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) TimestampType(org.voltdb.types.TimestampType) VoltTable(org.voltdb.VoltTable)

Example 80 with UnsupportedEncodingException

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

the class DeletesClient method validateSnapshot.

// stolen from TestSaveRestoreSysproc
static void validateSnapshot() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream original = System.out;
    try {
        System.setOut(ps);
        String[] args = new String[] { m_snapshotId, "--dir", m_snapshotDir };
        SnapshotVerifier.main(args);
        ps.flush();
        String reportString = baos.toString("UTF-8");
        if (reportString.startsWith("Snapshot corrupted")) {
            System.err.println(reportString);
            System.exit(-1);
        }
    } catch (UnsupportedEncodingException e) {
    } finally {
        System.setOut(original);
    }
}
Also used : PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

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