Skip to content

Commit a4a6fcf

Browse files
author
eugenp
committed
mostly doc and minor cleanup work
1 parent cfafcc5 commit a4a6fcf

File tree

5 files changed

+112
-6
lines changed

5 files changed

+112
-6
lines changed

core-java-8/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=========
22

3-
## Core Java Cookbooks and Examples
3+
## Core Java 8 Cookbooks and Examples
44

55
### Relevant Articles:
6-
// - [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
6+
// - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda)

core-java/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
## Core Java Cookbooks and Examples
44

55
### Relevant Articles:
6-
// - [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
6+
- [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list)
7+
- [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file)

core-java/pom.xml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
<version>4.0</version>
2323
</dependency>
2424

25+
<dependency>
26+
<groupId>commons-io</groupId>
27+
<artifactId>commons-io</artifactId>
28+
<version>2.4</version>
29+
</dependency>
30+
2531
<!-- web -->
2632

2733
<!-- marshalling -->
@@ -32,6 +38,31 @@
3238
<version>${jackson.version}</version>
3339
</dependency>
3440

41+
<!-- logging -->
42+
43+
<dependency>
44+
<groupId>org.slf4j</groupId>
45+
<artifactId>slf4j-api</artifactId>
46+
<version>${org.slf4j.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>ch.qos.logback</groupId>
50+
<artifactId>logback-classic</artifactId>
51+
<version>${logback.version}</version>
52+
<!-- <scope>runtime</scope> -->
53+
</dependency>
54+
<dependency>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>jcl-over-slf4j</artifactId>
57+
<version>${org.slf4j.version}</version>
58+
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
59+
</dependency>
60+
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
61+
<groupId>org.slf4j</groupId>
62+
<artifactId>log4j-over-slf4j</artifactId>
63+
<version>${org.slf4j.version}</version>
64+
</dependency>
65+
3566
<!-- test scoped -->
3667

3768
<dependency>
@@ -101,7 +132,7 @@
101132

102133
<!-- persistence -->
103134
<hibernate.version>4.3.0.Final</hibernate.version>
104-
<mysql-connector-java.version>5.1.27</mysql-connector-java.version>
135+
<mysql-connector-java.version>5.1.28</mysql-connector-java.version>
105136

106137
<!-- marshalling -->
107138
<jackson.version>2.3.0</jackson.version>
Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,82 @@
11
package org.baeldung.java;
22

3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.util.Scanner;
7+
8+
import org.apache.commons.io.FileUtils;
39
import org.junit.Test;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
13+
import com.google.common.base.Charsets;
14+
import com.google.common.io.Files;
415

516
public class CoreJavaIoUnitTest {
17+
protected final Logger logger = LoggerFactory.getLogger(getClass());
618

719
// tests -
820

921
@Test
10-
public final void whenIteratingAFile_thenCorrect() {
11-
//
22+
public final void givenUsingGuava_whenIteratingAFile_thenCorrect() throws IOException {
23+
final String path = "G:\\full\\train\\input\\" + "trainDataNegative.csv";
24+
// final String path = "G:\\full\\train\\input\\" + "trainDataPositive.csv";
25+
26+
logMemory();
27+
Files.readLines(new File(path), Charsets.UTF_8);
28+
logMemory();
29+
}
30+
31+
@Test
32+
public final void givenUsingCommonsIo_whenIteratingAFile_thenCorrect() throws IOException {
33+
final String path = "G:\\full\\train\\input\\" + "trainDataNegative.csv";
34+
// final String path = "G:\\full\\train\\input\\" + "trainDataPositive.csv";
35+
36+
logMemory();
37+
FileUtils.readLines(new File(path));
38+
logMemory();
39+
}
40+
41+
@Test
42+
public final void whenStreamingThroughAFile_thenCorrect() throws IOException {
43+
final String path = "G:\\full\\train\\input\\" + "trainDataNegative.csv";
44+
// final String path = "G:\\full\\train\\input\\" + "trainDataPositive.csv";
45+
46+
logMemory();
47+
48+
FileInputStream inputStream = null;
49+
Scanner sc = null;
50+
try {
51+
inputStream = new FileInputStream(path);
52+
sc = new Scanner(inputStream, "UTF-8");
53+
while (sc.hasNextLine()) {
54+
final String line = sc.nextLine();
55+
// System.out.println(line);
56+
}
57+
// note that Scanner suppresses exceptions
58+
if (sc.ioException() != null) {
59+
throw sc.ioException();
60+
}
61+
} finally {
62+
if (inputStream != null) {
63+
inputStream.close();
64+
}
65+
if (sc != null) {
66+
sc.close();
67+
}
68+
}
69+
70+
logMemory();
71+
}
72+
73+
//
74+
75+
private final void logMemory() {
76+
logger.info("Max Memory: {} Mb", Runtime.getRuntime().maxMemory() / 1048576);
77+
logger.info("Total Memory: {} Mb", Runtime.getRuntime().totalMemory() / 1048576);
78+
logger.info("Free Memory: {} Mb", Runtime.getRuntime().freeMemory() / 1048576);
1279
}
1380

1481
}
82+
//

httpclient/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44

55

66
### Relevant Articles:
7+
8+
- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies)
9+
- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code)
10+
- [HttpClient 4 – Cancel / Abort Request](http://www.baeldung.com/httpclient-cancel-request)
711
- [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4)
12+
- [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient)
13+
- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl)

0 commit comments

Comments
 (0)