Migration Deep Dive für 17 · Java I/O und NIO öffnen →
⌂ ÜbersichtAlle Vergleiche
Modul 17 · 100 % Codeabdeckung

Java I/O und NIO

Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.

3Legacy-Dateien
3Modern-Dateien
78 → 80Codezeilen
7/7vollständig erfasst

Fachliche Einordnung

Legacy

File und manuelle Streams

Streams, Buffer und Close-Logik werden manuell verwaltet.

Modern

Path und Files

Files.copy übernimmt Kopieren und Ressourcenverwaltung; Path ist die zentrale Abstraktion.

Vergleichsfokus: Alle Dateien werden nach technischer Rolle und fachlicher Verantwortung gruppiert.
Wichtige Abgrenzung: One-to-many-Änderungen werden als Gruppe dargestellt; eine künstliche 1:1-Zuordnung wird vermieden.

Vollständige Abdeckungsmatrix

Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.

VergleichsgruppeLegacy-DateienModern-DateienLegacy-ZeilenModern-ZeilenÄhnlichkeit
Build-Konfiguration113434100%
Dateiservice und Test22444613%

Gemeinsame Modulstruktur

Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.

Gemeinsam · 19 Zeilenpom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>at.aydin.academy</groupId>
        <artifactId>java-modernization-deep-dive</artifactId>
        <version>1.0.0</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>17ionio-pair</artifactId>
    <packaging>pom</packaging>
    <name>Java I/O und NIO: Legacy und Modern</name>
    <modules>
        <module>legacy</module>
        <module>modern</module>
    </modules>
</project>

Alle semantischen Codevergleiche

01Build-KonfigurationDirektvergleich · Legacy 34 / Modern 34 Zeilen · Ähnlichkeit 100%

I/O-Testkonfiguration wird verglichen.

Legacy-DateienModern-DateienEinordnung
pom.xmlpom.xmlDirektvergleich
Semantische Ähnlichkeit: 100%

Legacy

Legacy · 34 Zeilenlegacy/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>17ionio-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>io-legacy</artifactId>
            <packaging>jar</packaging>
            <name>I/O Legacy</name>

            <dependencies>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </project>

Modern

Modern · 34 Zeilenmodern/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>17ionio-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>nio-modern</artifactId>
            <packaging>jar</packaging>
            <name>NIO Modern</name>

            <dependencies>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </project>
02Dateiservice und TestDirektvergleich · Legacy 44 / Modern 46 Zeilen · Ähnlichkeit 13%

Stream-basierte Kopie wird NIO-Path/Files-API gegenübergestellt.

Legacy-DateienModern-DateienEinordnung
LegacyFileCopy.java
LegacyFileCopyTest.java
PathFileService.java
PathFileServiceTest.java
Direktvergleich
Semantische Ähnlichkeit: 13%

Legacy

package at.aydin.lab.io.legacy;

// Design Pattern: Adapter – kapselt streambasiertes Kopieren hinter einer kleinen Datei-API.
import java.io.*;

public final class LegacyFileCopy {
    public long copy(File source, File target) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        long bytes = 0;
        try {
            in = new FileInputStream(source);
            out = new FileOutputStream(target);
            byte[] buffer = new byte[4096];
            int read;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
                bytes += read;
            }
            return bytes;
        } finally {
            if (in != null) try {
                in.close();
            } catch (IOException ignored) {
            }
            if (out != null) out.close();
        }
    }
}
package at.aydin.lab.io.legacy;

import org.junit.jupiter.api.Test;
import java.nio.file.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

class LegacyFileCopyTest {
    @Test
    void copiesFile() throws Exception {
        Path a = Files.createTempFile("a", "txt"), b = Files.createTempFile("b", "txt");
        Files.writeString(a, "abc");
        assertEquals(3, new LegacyFileCopy().copy(a.toFile(), b.toFile()));
        assertEquals("abc", Files.readString(b));
    }
}

Modern

package at.aydin.lab.io.modern;

import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.zip.*;

// Design Pattern: Adapter
// Zweck: Fachliche Dateioperationen werden hinter der modernen Path-/Files-API gebündelt.
public final class PathFileService {
    public long copy(Path source, Path target) throws IOException {
        Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
        return Files.size(target);
    }

    public List<Path> find(Path root, String suffix) throws IOException {
        try (var paths = Files.walk(root)) {
            return paths.filter(Files::isRegularFile).filter(p -> p.getFileName().toString().endsWith(suffix)).sorted()
                    .toList();
        }
    }

    public void zip(Path source, Path zip) throws IOException {
        try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(zip))) {
            out.putNextEntry(new ZipEntry(source.getFileName().toString()));
            Files.copy(source, out);
            out.closeEntry();
        }
    }
}
package at.aydin.lab.io.modern;

import org.junit.jupiter.api.Test;
import java.nio.file.*;
import static org.junit.jupiter.api.Assertions.*;

class PathFileServiceTest {
    @Test
    void copiesAndFinds() throws Exception {
        Path dir = Files.createTempDirectory("nio"), a = dir.resolve("a.txt"), b = dir.resolve("b.txt");
        Files.writeString(a, "abc");
        var s = new PathFileService();
        assertEquals(3, s.copy(a, b));
        assertEquals(2, s.find(dir, ".txt").size());
    }
}
⌂ Cockpit