Search in sources :

Example 1 with BackendAIOConnection

use of com.actiontech.dble.net.BackendAIOConnection in project dble by actiontech.

the class LoadDataUtil method requestFileDataResponse.

public static void requestFileDataResponse(byte[] data, BackendConnection conn) {
    byte packId = data[3];
    BackendAIOConnection backendAIOConnection = (BackendAIOConnection) conn;
    RouteResultsetNode rrn = (RouteResultsetNode) conn.getAttachment();
    LoadData loadData = rrn.getLoadData();
    List<String> loadDataData = loadData.getData();
    try {
        if (loadDataData != null && loadDataData.size() > 0) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            for (int i = 0, loadDataDataSize = loadDataData.size(); i < loadDataDataSize; i++) {
                String line = loadDataData.get(i);
                String s = (i == loadDataDataSize - 1) ? line : line + loadData.getLineTerminatedBy();
                byte[] bytes = s.getBytes(CharsetUtil.getJavaCharset(loadData.getCharset()));
                bos.write(bytes);
            }
            packId = writeToBackConnection(packId, new ByteArrayInputStream(bos.toByteArray()), backendAIOConnection);
        } else {
            packId = writeToBackConnection(packId, new BufferedInputStream(new FileInputStream(loadData.getFileName())), backendAIOConnection);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        // send empty packet
        byte[] empty = new byte[] { 0, 0, 0, 3 };
        empty[3] = ++packId;
        backendAIOConnection.write(empty);
    }
}
Also used : LoadData(com.actiontech.dble.sqlengine.mpp.LoadData) BackendAIOConnection(com.actiontech.dble.net.BackendAIOConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Aggregations

BackendAIOConnection (com.actiontech.dble.net.BackendAIOConnection)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1 LoadData (com.actiontech.dble.sqlengine.mpp.LoadData)1