public static void concat()

in src/main/java/com/microsoft/azure/datalake/store/Core.java [593:658]


    public static void concat(String path,
                              List<String> sources,
                              ADLStoreClient client,
                              boolean deleteSourceDirectory,
                              RequestOptions opts,
                              OperationResponse resp) {
        if (sources == null || sources.size() == 0 ) {
            resp.successful = false;
            resp.message = "No source files specified to concatenate";
            return;
        }
        byte[] body = null;
        JsonStringEncoder jsonEncoder = JsonStringEncoder.getInstance();
        StringBuilder sb = new StringBuilder("{\"sources\":[");
        boolean firstelem = true;
        HashSet<String> pathSet = new HashSet<String>(4096);  // 4096: reasonably large-enough number for "most" cases
        for (String item : sources) {
            if (item.equals(path)) {
                resp.successful = false;
                resp.message = "One of the source files to concatenate is the destination file";
                return;
            }

            // check that each source path occurs only once
            if (pathSet.contains(item)) {
                resp.successful = false;
                resp.message = "concat() source list contains a file more than once: " + item;
                return;
            } else {
                pathSet.add(item);
            }

            // prepend Filesystem prefix if needed to each of the paths
            String prefix = client.getFilePathPrefix();
            if (prefix!=null) {
                if (item.charAt(0) == '/') {
                    item = prefix + item;
                } else {
                    item = prefix + "/" + item;
                }
            }

            if (!firstelem) {
                sb.append(',');
            }
            else {
                firstelem = false;
            }
            sb.append("\"").append(jsonEncoder.quoteAsString(item)).append("\"");
        }
        sb.append("]}");
        try {
            body = sb.toString().getBytes("UTF-8");
        } catch (UnsupportedEncodingException ex) {
            //This should't happen.
            assert false : "UTF-8 encoding is not supported";
        }

        QueryParams qp = null;
        if (deleteSourceDirectory) {
            qp = new QueryParams();
            qp.add("deleteSourceDirectory", "true");
        }

        HttpTransport.makeCall(client, Operation.MSCONCAT, path, qp, body, 0, body.length, opts, resp);
    }