A java library to read and write text file in streaming
To use this library in your Java project, add the following dependency to your Maven pom.xml
file:
<dependency>
<groupId>io.github.dumijdev</groupId>
<artifactId>file-stream</artifactId>
<version>0.0.1</version>
</dependency>
Explain how to incorporate and use the library in a Java project.
// Example code snippet
import io.github.dumijdev.filestream.model.ReaderFileStream;
import io.github.dumijdev.filestream.model.WriterFileStream;
import io.github.dumijdev.filestream.model.WriterFileStreamImpl;
import java.io.File;
import java.nio.file.Files;
public class Example {
public static void main(String[] args) {
var file = new File("example.txt");
var reader = new ReaderFileStreamImpl();
var dataStream = readerFileStream.read(file);
while (dataStream.hasNext()) {
System.out.println(dataStream.next());
}
File fileOut = Files.createTempFile("test", ".txt").toFile();
var writer = new WriterFileStreamImpl();
var stream = readerFileStream.read(fileIn);
writerFileStream.write(stream, fileOut);
}
}
We welcome contributions! Follow these steps:
- Fork the project.
- Create your feature branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
Provide examples of how to use your library. You can base these examples on your tests.
Demonstrate how to use the library to read files.
import io.github.dumijdev.filestream.model.ReaderFileStreamImpl;
import java.io.File;
import java.io.IOException;
public class Example1 {
public static void main(String[] args) throws InterruptedException, IOException {
var file = new File("example.txt");
var reader = new ReaderFileStreamImpl();
var dataStream = reader.read(file);
while (dataStream.hasNext()) {
System.out.println(dataStream.next());
}
}
}
Show how to write files with a custom transformation.
import io.github.dumijdev.filestream.model.FileDataStream;
import io.github.dumijdev.filestream.model.WriterFileStreamImpl;
import java.io.File;
import java.nio.file.Files;
public class Example2 {
public static void main(String[] args) {
File fileOut = Files.createTempFile("test", ".txt").toFile();
var writer = new WriterFileStreamImpl();
var stream = new FileDataStream<>();
writer.write(stream, fileOut, item -> item.toString().toUpperCase());
}
}
This library is licensed under the MIT - see the LICENSE file for details.