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);
}
}
Aggregations