Search in sources :

Example 16 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project hive by apache.

the class SQLOperation method setupSessionIO.

private void setupSessionIO(SessionState sessionState) {
    try {
        // hive server's session input stream is not used
        sessionState.in = null;
        sessionState.out = new PrintStream(System.out, true, CharEncoding.UTF_8);
        sessionState.info = new PrintStream(System.err, true, CharEncoding.UTF_8);
        sessionState.err = new PrintStream(System.err, true, CharEncoding.UTF_8);
    } catch (UnsupportedEncodingException e) {
        LOG.error("Error creating PrintStream", e);
        e.printStackTrace();
        sessionState.out = null;
        sessionState.info = null;
        sessionState.err = null;
    }
}
Also used : PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 17 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project hive by apache.

the class SQLOperation method decodeFromString.

private RowSet decodeFromString(List<Object> rows, RowSet rowSet) throws SQLException, SerDeException {
    getSerDe();
    StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector();
    List<? extends StructField> fieldRefs = soi.getAllStructFieldRefs();
    Object[] deserializedFields = new Object[fieldRefs.size()];
    Object rowObj;
    ObjectInspector fieldOI;
    int protocol = getProtocolVersion().getValue();
    for (Object rowString : rows) {
        try {
            rowObj = serde.deserialize(new BytesWritable(((String) rowString).getBytes("UTF-8")));
        } catch (UnsupportedEncodingException e) {
            throw new SerDeException(e);
        }
        for (int i = 0; i < fieldRefs.size(); i++) {
            StructField fieldRef = fieldRefs.get(i);
            fieldOI = fieldRef.getFieldObjectInspector();
            Object fieldData = soi.getStructFieldData(rowObj, fieldRef);
            deserializedFields[i] = SerDeUtils.toThriftPayload(fieldData, fieldOI, protocol);
        }
        rowSet.addRow(deserializedFields);
    }
    return rowSet;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BytesWritable(org.apache.hadoop.io.BytesWritable) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Example 18 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project storm by apache.

the class JsonSerializer method initialize.

public void initialize(OutputStream processIn, InputStream processOut) {
    try {
        this.processIn = new BufferedWriter(new OutputStreamWriter(processIn, DEFAULT_CHARSET));
        this.processOut = new BufferedReader(new InputStreamReader(processOut, DEFAULT_CHARSET));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 19 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project hive by apache.

the class HiveBaseResultSet method getBinaryStream.

public InputStream getBinaryStream(int columnIndex) throws SQLException {
    Object obj = getObject(columnIndex);
    if (obj == null) {
        return null;
    } else if (obj instanceof InputStream) {
        return (InputStream) obj;
    } else if (obj instanceof byte[]) {
        byte[] byteArray = (byte[]) obj;
        InputStream is = new ByteArrayInputStream(byteArray);
        return is;
    } else if (obj instanceof String) {
        String str = (String) obj;
        InputStream is = null;
        try {
            is = new ByteArrayInputStream(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new SQLException("Illegal conversion to binary stream from column " + columnIndex + " - Unsupported encoding exception");
        }
        return is;
    }
    throw new SQLException("Illegal conversion to binary stream from column " + columnIndex);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 20 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project storm by apache.

the class JSONOpaqueSerializer method serialize.

@Override
public byte[] serialize(OpaqueValue obj) {
    List toSer = new ArrayList(3);
    toSer.add(obj.currTxid);
    toSer.add(obj.curr);
    toSer.add(obj.prev);
    try {
        return JSONValue.toJSONString(toSer).getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1228 IOException (java.io.IOException)338 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)137 ArrayList (java.util.ArrayList)111 File (java.io.File)109 ByteArrayOutputStream (java.io.ByteArrayOutputStream)99 MessageDigest (java.security.MessageDigest)80 ByteArrayInputStream (java.io.ByteArrayInputStream)79 InputStream (java.io.InputStream)79 InputStreamReader (java.io.InputStreamReader)73 FileNotFoundException (java.io.FileNotFoundException)71 OutputStreamWriter (java.io.OutputStreamWriter)69 BufferedReader (java.io.BufferedReader)58 URL (java.net.URL)55 FileOutputStream (java.io.FileOutputStream)52 Map (java.util.Map)52 HashMap (java.util.HashMap)48 JSONException (org.json.JSONException)44 List (java.util.List)41 PrintStream (java.io.PrintStream)39