mostly doc and minor cleanup work
This commit is contained in:
parent
cfafcc57b7
commit
a4a6fcf569
|
@ -1,6 +1,6 @@
|
||||||
=========
|
=========
|
||||||
|
|
||||||
## Core Java Cookbooks and Examples
|
## Core Java 8 Cookbooks and Examples
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
// - [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
|
// - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda)
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
## Core Java Cookbooks and Examples
|
## Core Java Cookbooks and Examples
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
// - [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
|
- [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list)
|
||||||
|
- [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file)
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
<version>4.0</version>
|
<version>4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- web -->
|
<!-- web -->
|
||||||
|
|
||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
|
@ -32,6 +38,31 @@
|
||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- logging -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
<!-- <scope>runtime</scope> -->
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||||
|
</dependency>
|
||||||
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -101,7 +132,7 @@
|
||||||
|
|
||||||
<!-- persistence -->
|
<!-- persistence -->
|
||||||
<hibernate.version>4.3.0.Final</hibernate.version>
|
<hibernate.version>4.3.0.Final</hibernate.version>
|
||||||
<mysql-connector-java.version>5.1.27</mysql-connector-java.version>
|
<mysql-connector-java.version>5.1.28</mysql-connector-java.version>
|
||||||
|
|
||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.3.0</jackson.version>
|
<jackson.version>2.3.0</jackson.version>
|
||||||
|
|
|
@ -1,14 +1,82 @@
|
||||||
package org.baeldung.java;
|
package org.baeldung.java;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
public class CoreJavaIoUnitTest {
|
public class CoreJavaIoUnitTest {
|
||||||
|
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
// tests -
|
// tests -
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void whenIteratingAFile_thenCorrect() {
|
public final void givenUsingGuava_whenIteratingAFile_thenCorrect() throws IOException {
|
||||||
//
|
final String path = "G:\\full\\train\\input\\" + "trainDataNegative.csv";
|
||||||
|
// final String path = "G:\\full\\train\\input\\" + "trainDataPositive.csv";
|
||||||
|
|
||||||
|
logMemory();
|
||||||
|
Files.readLines(new File(path), Charsets.UTF_8);
|
||||||
|
logMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenUsingCommonsIo_whenIteratingAFile_thenCorrect() throws IOException {
|
||||||
|
final String path = "G:\\full\\train\\input\\" + "trainDataNegative.csv";
|
||||||
|
// final String path = "G:\\full\\train\\input\\" + "trainDataPositive.csv";
|
||||||
|
|
||||||
|
logMemory();
|
||||||
|
FileUtils.readLines(new File(path));
|
||||||
|
logMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void whenStreamingThroughAFile_thenCorrect() throws IOException {
|
||||||
|
final String path = "G:\\full\\train\\input\\" + "trainDataNegative.csv";
|
||||||
|
// final String path = "G:\\full\\train\\input\\" + "trainDataPositive.csv";
|
||||||
|
|
||||||
|
logMemory();
|
||||||
|
|
||||||
|
FileInputStream inputStream = null;
|
||||||
|
Scanner sc = null;
|
||||||
|
try {
|
||||||
|
inputStream = new FileInputStream(path);
|
||||||
|
sc = new Scanner(inputStream, "UTF-8");
|
||||||
|
while (sc.hasNextLine()) {
|
||||||
|
final String line = sc.nextLine();
|
||||||
|
// System.out.println(line);
|
||||||
|
}
|
||||||
|
// note that Scanner suppresses exceptions
|
||||||
|
if (sc.ioException() != null) {
|
||||||
|
throw sc.ioException();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
if (sc != null) {
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
private final void logMemory() {
|
||||||
|
logger.info("Max Memory: {} Mb", Runtime.getRuntime().maxMemory() / 1048576);
|
||||||
|
logger.info("Total Memory: {} Mb", Runtime.getRuntime().totalMemory() / 1048576);
|
||||||
|
logger.info("Free Memory: {} Mb", Runtime.getRuntime().freeMemory() / 1048576);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//
|
|
@ -4,4 +4,10 @@
|
||||||
|
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies)
|
||||||
|
- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code)
|
||||||
|
- [HttpClient 4 – Cancel / Abort Request](http://www.baeldung.com/httpclient-cancel-request)
|
||||||
- [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4)
|
- [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4)
|
||||||
|
- [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient)
|
||||||
|
- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl)
|
||||||
|
|
Loading…
Reference in New Issue