CPD Results

The following document contains the results of PMD's CPD 6.55.0.

Duplications

File Line
org/eclipse/aether/internal/impl/DefaultFileProcessor.java 94
org/eclipse/aether/internal/impl/DefaultPathProcessor.java 58
FileUtils.CollocatedTempFile tempTarget = FileUtils.newTempFile(target.toPath());
                OutputStream out = new BufferedOutputStream(Files.newOutputStream(tempTarget.getPath()))) {
            long result = copy(out, in, listener);
            tempTarget.move();
            return result;
        }
    }

    private long copy(OutputStream os, InputStream is, ProgressListener listener) throws IOException {
        long total = 0L;
        byte[] buffer = new byte[1024 * 32];
        while (true) {
            int bytes = is.read(buffer);
            if (bytes < 0) {
                break;
            }

            os.write(buffer, 0, bytes);

            total += bytes;

            if (listener != null && bytes > 0) {
                try {
                    listener.progressed(ByteBuffer.wrap(buffer, 0, bytes));
                } catch (Exception e) {
                    // too bad
                }
            }
        }

        return total;
    }

    @Override
    public void move(File source, File target) throws IOException {
File Line
org/eclipse/aether/internal/impl/DefaultChecksumProcessor.java 53
org/eclipse/aether/internal/impl/DefaultFileProcessor.java 143
try (BufferedReader br = Files.newBufferedReader(checksumPath, StandardCharsets.UTF_8)) {
            while (true) {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                line = line.trim();
                if (!line.isEmpty()) {
                    checksum = line;
                    break;
                }
            }
        }

        if (checksum.matches(".+= [0-9A-Fa-f]+")) {
            int lastSpacePos = checksum.lastIndexOf(' ');
            checksum = checksum.substring(lastSpacePos + 1);
        } else {
            int spacePos = checksum.indexOf(' ');

            if (spacePos != -1) {
                checksum = checksum.substring(0, spacePos);
            }
        }

        return checksum;
    }

    @Override
    public void writeChecksum(Path target, String checksum) throws IOException {
File Line
org/eclipse/aether/internal/impl/DefaultLocalPathComposer.java 72
org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactory.java 211
StringBuilder path = new StringBuilder(128);

        if (!metadata.getGroupId().isEmpty()) {
            path.append(metadata.getGroupId().replace('.', '/')).append('/');

            if (!metadata.getArtifactId().isEmpty()) {
                path.append(metadata.getArtifactId()).append('/');

                if (!metadata.getVersion().isEmpty()) {
                    path.append(metadata.getVersion()).append('/');
                }
            }
        }

        path.append(insertRepositoryKey(metadata.getType(), repositoryKey));