Skip to content

Commit 0a40f30

Browse files
author
orrym
committed
Merge branch 'master' of https://github.com/eugenp/tutorials
2 parents 48e5d41 + 103e6b6 commit 0a40f30

339 files changed

Lines changed: 2753 additions & 3505 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎core-java-8/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@
4141
- [Primitive Type Streams in Java 8](http://www.baeldung.com/java-8-primitive-streams)
4242
- [Fail-Safe Iterator vs Fail-Fast Iterator](http://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)
4343
- [Shuffling Collections In Java](http://www.baeldung.com/java-shuffle-collection)
44+
- [Java 8 StringJoiner](http://www.baeldung.com/java-string-joiner)
45+
- [Introduction to Spliterator in Java](http://www.baeldung.com/java-spliterator)

‎core-java-io/.gitignore‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
*.class
2-
31
0.*
42

5-
#folders#
6-
/target
7-
/neoDb*
8-
/data
9-
/src/main/webapp/WEB-INF/classes
10-
*/META-INF/*
11-
.resourceCache
12-
13-
# Packaged files #
14-
*.jar
15-
*.war
16-
*.ear
17-
183
# Files generated by integration tests
19-
*.txt
20-
backup-pom.xml
21-
/bin/
22-
/temp
23-
24-
#IntelliJ specific
25-
.idea/
26-
*.iml
4+
# *.txt
5+
/temp

‎core-java-io/pom.xml‎

Lines changed: 7 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
32
<modelVersion>4.0.0</modelVersion>
43
<groupId>com.baeldung</groupId>
54
<artifactId>core-java-io</artifactId>
@@ -211,16 +210,6 @@
211210
<artifactId>jmh-generator-annprocess</artifactId>
212211
<version>1.19</version>
213212
</dependency>
214-
<dependency>
215-
<groupId>org.springframework</groupId>
216-
<artifactId>spring-web</artifactId>
217-
<version>4.3.4.RELEASE</version>
218-
</dependency>
219-
<dependency>
220-
<groupId>org.springframework.boot</groupId>
221-
<artifactId>spring-boot-starter</artifactId>
222-
<version>1.5.8.RELEASE</version>
223-
</dependency>
224213
<dependency>
225214
<groupId>org.hsqldb</groupId>
226215
<artifactId>hsqldb</artifactId>
@@ -264,99 +253,6 @@
264253
</configuration>
265254
</plugin>
266255

267-
<plugin>
268-
<groupId>org.apache.maven.plugins</groupId>
269-
<artifactId>maven-dependency-plugin</artifactId>
270-
<executions>
271-
<execution>
272-
<id>copy-dependencies</id>
273-
<phase>prepare-package</phase>
274-
<goals>
275-
<goal>copy-dependencies</goal>
276-
</goals>
277-
<configuration>
278-
<outputDirectory>${project.build.directory}/libs</outputDirectory>
279-
</configuration>
280-
</execution>
281-
</executions>
282-
</plugin>
283-
284-
<plugin>
285-
<groupId>org.apache.maven.plugins</groupId>
286-
<artifactId>maven-jar-plugin</artifactId>
287-
<configuration>
288-
<archive>
289-
<manifest>
290-
<addClasspath>true</addClasspath>
291-
<classpathPrefix>libs/</classpathPrefix>
292-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
293-
</manifest>
294-
</archive>
295-
</configuration>
296-
</plugin>
297-
298-
<plugin>
299-
<groupId>org.apache.maven.plugins</groupId>
300-
<artifactId>maven-assembly-plugin</artifactId>
301-
<executions>
302-
<execution>
303-
<phase>package</phase>
304-
<goals>
305-
<goal>single</goal>
306-
</goals>
307-
<configuration>
308-
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
309-
<archive>
310-
<manifest>
311-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
312-
</manifest>
313-
</archive>
314-
<descriptorRefs>
315-
<descriptorRef>jar-with-dependencies</descriptorRef>
316-
</descriptorRefs>
317-
</configuration>
318-
</execution>
319-
</executions>
320-
</plugin>
321-
322-
<plugin>
323-
<groupId>org.apache.maven.plugins</groupId>
324-
<artifactId>maven-shade-plugin</artifactId>
325-
<executions>
326-
<execution>
327-
<goals>
328-
<goal>shade</goal>
329-
</goals>
330-
<configuration>
331-
<shadedArtifactAttached>true</shadedArtifactAttached>
332-
<transformers>
333-
<transformer
334-
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
335-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
336-
</transformer>
337-
</transformers>
338-
</configuration>
339-
</execution>
340-
</executions>
341-
</plugin>
342-
343-
<plugin>
344-
<groupId>com.jolira</groupId>
345-
<artifactId>onejar-maven-plugin</artifactId>
346-
<executions>
347-
<execution>
348-
<configuration>
349-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
350-
<attachToBuild>true</attachToBuild>
351-
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
352-
</configuration>
353-
<goals>
354-
<goal>one-jar</goal>
355-
</goals>
356-
</execution>
357-
</executions>
358-
</plugin>
359-
360256
<plugin>
361257
<groupId>org.springframework.boot</groupId>
362258
<artifactId>spring-boot-maven-plugin</artifactId>
@@ -384,19 +280,19 @@
384280
<argument>-Xmx300m</argument>
385281
<argument>-XX:+UseParallelGC</argument>
386282
<argument>-classpath</argument>
387-
<classpath/>
283+
<classpath />
388284
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
389285
</arguments>
390286
</configuration>
391287
</plugin>
392-
288+
393289
<plugin>
394290
<groupId>org.apache.maven.plugins</groupId>
395291
<artifactId>maven-javadoc-plugin</artifactId>
396292
<version>3.0.0-M1</version>
397293
<configuration>
398294
<source>1.8</source>
399-
<target>1.8</target>
295+
<target>1.8</target>
400296
</configuration>
401297
</plugin>
402298

@@ -442,7 +338,7 @@
442338
<executions>
443339
<execution>
444340
<id>run-benchmarks</id>
445-
<!-- <phase>integration-test</phase>-->
341+
<!-- <phase>integration-test</phase> -->
446342
<phase>none</phase>
447343
<goals>
448344
<goal>exec</goal>
@@ -452,7 +348,7 @@
452348
<executable>java</executable>
453349
<arguments>
454350
<argument>-classpath</argument>
455-
<classpath/>
351+
<classpath />
456352
<argument>org.openjdk.jmh.Main</argument>
457353
<argument>.*</argument>
458354
</arguments>
@@ -490,7 +386,7 @@
490386
<protonpack.version>1.13</protonpack.version>
491387
<streamex.version>0.6.5</streamex.version>
492388
<vavr.version>0.9.0</vavr.version>
493-
389+
494390
<!-- testing -->
495391
<org.hamcrest.version>1.3</org.hamcrest.version>
496392
<junit.version>4.12</junit.version>

‎core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.nio.file.WatchService;
1111

1212
public class DirectoryWatcherExample {
13-
13+
1414
public static void main(String[] args) throws IOException, InterruptedException {
1515
WatchService watchService = FileSystems.getDefault().newWatchService();
1616
Path path = Paths.get(System.getProperty("user.home"));
@@ -25,5 +25,5 @@ public static void main(String[] args) throws IOException, InterruptedException
2525

2626
watchService.close();
2727
}
28-
28+
2929
}

‎core-java-io/src/main/resources/targetFile.tmp‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎core-java-io/src/test/java/com/baeldung/copyfiles/FileCopierTest.java‎

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,51 @@
1919
import static org.assertj.core.api.Assertions.*;
2020

2121
public class FileCopierTest {
22-
File original = new File("src/test/resources/original.txt");
22+
File original = new File("src/test/resources/original.txt");
2323

24-
@Before
25-
public void init() throws IOException {
26-
if (!original.exists())
27-
Files.createFile(original.toPath());
28-
}
24+
@Before
25+
public void init() throws IOException {
26+
if (!original.exists())
27+
Files.createFile(original.toPath());
28+
}
2929

30-
@Test
31-
public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException {
32-
File copied = new File("src/test/resources/copiedWithIo.txt");
33-
try (InputStream in = new BufferedInputStream(new FileInputStream(original));
34-
OutputStream out = new BufferedOutputStream(new FileOutputStream(copied))) {
35-
byte[] buffer = new byte[1024];
36-
int lengthRead;
37-
while ((lengthRead = in.read(buffer)) > 0) {
38-
out.write(buffer, 0, lengthRead);
39-
out.flush();
40-
}
41-
}
42-
assertThat(copied).exists();
43-
assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath())));
44-
}
30+
@Test
31+
public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException {
32+
File copied = new File("src/test/resources/copiedWithIo.txt");
33+
try (InputStream in = new BufferedInputStream(new FileInputStream(original)); OutputStream out = new BufferedOutputStream(new FileOutputStream(copied))) {
34+
byte[] buffer = new byte[1024];
35+
int lengthRead;
36+
while ((lengthRead = in.read(buffer)) > 0) {
37+
out.write(buffer, 0, lengthRead);
38+
out.flush();
39+
}
40+
}
41+
assertThat(copied).exists();
42+
assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath())));
43+
}
4544

46-
@Test
47-
public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException {
48-
File copied = new File("src/test/resources/copiedWithApacheCommons.txt");
49-
FileUtils.copyFile(original, copied);
50-
assertThat(copied).exists();
51-
assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath())));
52-
}
45+
@Test
46+
public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException {
47+
File copied = new File("src/test/resources/copiedWithApacheCommons.txt");
48+
FileUtils.copyFile(original, copied);
49+
assertThat(copied).exists();
50+
assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath())));
51+
}
5352

54-
@Test
55-
public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException {
56-
Path copied = Paths.get("src/test/resources/copiedWithNio.txt");
57-
Path originalPath = original.toPath();
58-
Files.copy(originalPath, copied, StandardCopyOption.REPLACE_EXISTING);
59-
assertThat(copied).exists();
60-
assertThat(Files.readAllLines(originalPath).equals(Files.readAllLines(copied)));
61-
}
53+
@Test
54+
public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException {
55+
Path copied = Paths.get("src/test/resources/copiedWithNio.txt");
56+
Path originalPath = original.toPath();
57+
Files.copy(originalPath, copied, StandardCopyOption.REPLACE_EXISTING);
58+
assertThat(copied).exists();
59+
assertThat(Files.readAllLines(originalPath).equals(Files.readAllLines(copied)));
60+
}
6261

63-
@Test
64-
public void givenGuava_whenCopied_thenCopyExistsWithSameContents() throws IOException {
65-
File copied = new File("src/test/resources/copiedWithApacheCommons.txt");
66-
com.google.common.io.Files.copy(original, copied);
67-
assertThat(copied).exists();
68-
assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath())));
69-
}
62+
@Test
63+
public void givenGuava_whenCopied_thenCopyExistsWithSameContents() throws IOException {
64+
File copied = new File("src/test/resources/copiedWithApacheCommons.txt");
65+
com.google.common.io.Files.copy(original, copied);
66+
assertThat(copied).exists();
67+
assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath())));
68+
}
7069
}

‎core-java-io/src/test/java/com/baeldung/file/FileOperationsManualTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.apache.commons.io.FileUtils;
44
import org.hamcrest.CoreMatchers;
55
import org.hamcrest.Matchers;
6-
import org.junit.Assert;
76
import org.junit.Test;
87

98
import java.io.BufferedReader;

‎core-java-io/src/test/java/com/baeldung/file/FilesTest.java‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,22 @@ public void whenAppendToFileUsingGuava_thenCorrect() throws IOException {
4242
CharSink chs = com.google.common.io.Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND);
4343
chs.write("Spain\r\n");
4444

45-
assertThat(StreamUtils.getStringFromInputStream(
46-
new FileInputStream(fileName)))
47-
.isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
45+
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
4846
}
4947

50-
5148
@Test
5249
public void whenAppendToFileUsingFiles_thenCorrect() throws IOException {
5350
Files.write(Paths.get(fileName), "Spain\r\n".getBytes(), StandardOpenOption.APPEND);
5451

55-
assertThat(StreamUtils.getStringFromInputStream(
56-
new FileInputStream(fileName)))
57-
.isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
52+
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
5853
}
5954

6055
@Test
6156
public void whenAppendToFileUsingFileUtils_thenCorrect() throws IOException {
6257
File file = new File(fileName);
6358
FileUtils.writeStringToFile(file, "Spain\r\n", StandardCharsets.UTF_8, true);
6459

65-
assertThat(StreamUtils.getStringFromInputStream(
66-
new FileInputStream(fileName)))
67-
.isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
60+
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
6861
}
6962

7063
@Test
@@ -73,9 +66,7 @@ public void whenAppendToFileUsingFileOutputStream_thenCorrect() throws Exception
7366
fos.write("Spain\r\n".getBytes());
7467
fos.close();
7568

76-
assertThat(StreamUtils.getStringFromInputStream(
77-
new FileInputStream(fileName)))
78-
.isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
69+
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
7970
}
8071

8172
@Test
@@ -86,9 +77,6 @@ public void whenAppendToFileUsingFileWriter_thenCorrect() throws IOException {
8677
bw.newLine();
8778
bw.close();
8879

89-
assertThat(
90-
StreamUtils.getStringFromInputStream(
91-
new FileInputStream(fileName)))
92-
.isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
80+
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
9381
}
9482
}

‎core-java-io/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDIIntegrationTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void givenLookupFSJNDI_whengetInitialContextIsNotNull_thenSuccess() {
3535

3636
@Test
3737
public void givenInitialContext_whenLokupFileExists_thenSuccess() {
38-
File file = fsjndi.getFile(FILENAME);
39-
assertNotNull("File exists", file);
38+
File file = fsjndi.getFile(FILENAME);
39+
assertNotNull("File exists", file);
4040
}
4141
}

0 commit comments

Comments
 (0)