Skip to content

Commit

Permalink
[BAEL-19088] - Move articles out of core-java-io part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
catalin-burcea committed Nov 15, 2019
1 parent 0950c53 commit 5ec3630
Show file tree
Hide file tree
Showing 95 changed files with 114 additions and 180,090 deletions.
8 changes: 5 additions & 3 deletions core-java-modules/core-java-io-2/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Intellij
.idea/
*.iml
0.*

# Files generated by integration tests
# *.txt
/temp
13 changes: 12 additions & 1 deletion core-java-modules/core-java-io-2/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## Core Java IO

### Relevant Articles:
This module contains articles about core Java input and output (IO)

### Relevant Articles:
- [Create a File in a Specific Directory in Java](https://www.baeldung.com/java-create-file-in-directory)
- [How to Read a Large File Efficiently with Java](https://www.baeldung.com/java-read-lines-large-file)
- [Java – Write to File](https://www.baeldung.com/java-write-to-file)
- [FileNotFoundException in Java](https://www.baeldung.com/java-filenotfound-exception)
- [Delete the Contents of a File in Java](https://www.baeldung.com/java-delete-file-contents)
- [List Files in a Directory in Java](https://www.baeldung.com/java-list-directory-files)
- [Java – Append Data to a File](https://www.baeldung.com/java-append-to-file)
- [How to Copy a File with Java](https://www.baeldung.com/java-copy-file)
- [Create a Directory in Java](https://www.baeldung.com/java-create-directory)
- [[<-- Prev]](/core-java-modules/core-java-io)
212 changes: 4 additions & 208 deletions core-java-modules/core-java-io-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,16 @@
<dependencies>
<!-- utils -->
<dependency>
<groupId>net.sourceforge.collections</groupId>
<artifactId>collections-generic</artifactId>
<version>${collections-generic.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- utils -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>${commons-math3.version}</version>
</dependency>
<dependency>
<groupId>org.decimal4j</groupId>
<artifactId>decimal4j</artifactId>
<version>${decimal4j.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.unix4j</groupId>
<artifactId>unix4j-command</artifactId>
<version>${unix4j.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.grep4j</groupId>
<artifactId>grep4j</artifactId>
<version>${grep4j.version}</version>
</dependency>
<!-- web -->
<!-- marshalling -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>log4j</groupId>
Expand All @@ -78,99 +37,13 @@
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!-- test scoped -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${avaitility.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>${moneta.version}</version>
</dependency>
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>${esapi.version}</version>
</dependency>
<dependency>
<groupId>com.sun.messaging.mq</groupId>
<artifactId>fscontext</artifactId>
<version>${fscontext.version}</version>
</dependency>
<dependency>
<groupId>com.codepoetics</groupId>
<artifactId>protonpack</artifactId>
<version>${protonpack.version}</version>
</dependency>
<dependency>
<groupId>one.util</groupId>
<artifactId>streamex</artifactId>
<version>${streamex.version}</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>${vavr.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh-generator-annprocess.version}</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.asynchttpclient/async-http-client -->
<dependency>
<groupId>org.asynchttpclient</groupId>
<artifactId>async-http-client</artifactId>
<version>${async-http-client.version}</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
<scope>test</scope>
</dependency>
<!-- Mime Type Resolution Libraries -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>${tika.version}</version>
</dependency>
<dependency>
<groupId>net.sf.jmimemagic</groupId>
<artifactId>jmimemagic</artifactId>
<version>${jmime-magic.version}</version>
</dependency>
</dependencies>

<build>
Expand All @@ -182,22 +55,6 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<configuration>
<executable>java</executable>
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
<arguments>
<argument>-Xmx300m</argument>
<argument>-XX:+UseParallelGC</argument>
<argument>-classpath</argument>
<classpath />
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand All @@ -210,70 +67,9 @@
</plugins>
</build>

<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>

<executions>
<execution>
<id>run-benchmarks</id>
<!-- <phase>integration-test</phase> -->
<phase>none</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>org.openjdk.jmh.Main</argument>
<argument>.*</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<properties>

<!-- util -->
<bouncycastle.version>1.55</bouncycastle.version>
<commons-codec.version>1.10</commons-codec.version>
<commons-math3.version>3.6.1</commons-math3.version>
<decimal4j.version>1.0.3</decimal4j.version>
<commons-collections4.version>4.1</commons-collections4.version>
<collections-generic.version>4.01</collections-generic.version>
<unix4j.version>0.4</unix4j.version>
<grep4j.version>1.8.7</grep4j.version>
<fscontext.version>4.6-b01</fscontext.version>
<protonpack.version>1.13</protonpack.version>
<streamex.version>0.6.5</streamex.version>
<vavr.version>0.9.0</vavr.version>
<opencsv.version>4.1</opencsv.version>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<avaitility.version>1.7.0</avaitility.version>

<!-- maven plugins -->
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
<hsqldb.version>2.4.0</hsqldb.version>
<esapi.version>2.1.0.1</esapi.version>
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
<async-http-client.version>2.4.5</async-http-client.version>
<!-- Mime Type Libraries -->
<tika.version>1.18</tika.version>
<jmime-magic.version>0.1.5</jmime-magic.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.files;
package com.baeldung.listfiles;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.file;
package com.baeldung.appendtofile;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -22,9 +22,7 @@
import org.junit.Before;
import org.junit.Test;

import com.baeldung.util.StreamUtils;

public class FilesManualTest {
public class AppendToFileManualTest {

public static final String fileName = "src/main/resources/countries.properties";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.baeldung.util;
package com.baeldung.appendtofile;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;

import org.apache.commons.io.IOUtils;

public class StreamUtils {

public static String getStringFromInputStream(InputStream input) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@

import java.io.File;
import java.io.IOException;

import org.junit.BeforeClass;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class CreateFilesUnitTest {

@BeforeClass
public static void clean() {
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
File file1 = new File(tempDirectory.getAbsolutePath() + "/testFile.txt");
File file2 = new File(tempDirectory, "newFile.txt");
File file3 = new File(tempDirectory.getAbsolutePath() + File.separator + "newFile2.txt");
file1.delete();
file2.delete();
file3.delete();
}

@Test
public void givenAnExistingDirectory_whenCreatingAFileWithAbsolutePath_thenFileIsCreated() throws IOException {
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
File fileWithAbsolutePath = new File(tempDirectory.getAbsolutePath() + "/myDirectory/testFile.txt");
File fileWithAbsolutePath = new File(tempDirectory.getAbsolutePath() + "/testFile.txt");

assertFalse(fileWithAbsolutePath.exists());

Expand All @@ -25,7 +37,7 @@ public void givenAnExistingDirectory_whenCreatingAFileWithAbsolutePath_thenFileI
@Test
public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFileWithRelativePath_thenFileIsCreated() throws IOException {
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
File fileWithRelativePath = new File(tempDirectory, "myDirectory/newFile.txt");
File fileWithRelativePath = new File(tempDirectory, "newFile.txt");

assertFalse(fileWithRelativePath.exists());

Expand All @@ -37,7 +49,7 @@ public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFileWithRelativ
@Test
public void whenCreatingAFileWithFileSeparator_thenFileIsCreated() throws IOException {
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
File newFile = new File(tempDirectory.getAbsolutePath() + File.separator + "newFile.txt");
File newFile = new File(tempDirectory.getAbsolutePath() + File.separator + "newFile2.txt");

assertFalse(newFile.exists());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.file;
package com.baeldung.deletecontents;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -20,8 +20,6 @@
import org.junit.Before;
import org.junit.Test;

import com.baeldung.util.StreamUtils;

public class FilesClearDataUnitTest {

public static final String FILE_PATH = "src/test/resources/fileexample.txt";
Expand Down
Loading

0 comments on commit 5ec3630

Please sign in to comment.