JAVA-19116 Create new core-java-compiler sub module under core-java-modules (#13658)
* JAVA-19116 Create new core-java-compiler sub module under core-java-modules
This commit is contained in:
6
core-java-modules/core-java-compiler/README.md
Normal file
6
core-java-modules/core-java-compiler/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
## Core Java Compiler
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac)
|
||||
- [Illegal Character Compilation Error](https://www.baeldung.com/java-illegal-character-error)
|
||||
29
core-java-modules/core-java-compiler/pom.xml
Normal file
29
core-java-modules/core-java-compiler/pom.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-compiler</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-compiler</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.gdata</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>${gdata.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<gdata.version>1.47.1</gdata.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.javac;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Data {
|
||||
List<String> textList = new ArrayList();
|
||||
|
||||
public void addText(String text) {
|
||||
textList.add(text);
|
||||
}
|
||||
|
||||
public List getTextList() {
|
||||
return this.textList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
-d javac-target -verbose
|
||||
com/baeldung/javac/Data.java
|
||||
@@ -0,0 +1,2 @@
|
||||
-d javac-target
|
||||
-verbose
|
||||
@@ -0,0 +1 @@
|
||||
com/baeldung/javac/Data.java
|
||||
@@ -0,0 +1,3 @@
|
||||
-d javac-target
|
||||
-Xlint:rawtypes,unchecked,static,cast,serial,fallthrough
|
||||
com/baeldung/javac/Data.java
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.baeldung.illegalcharacter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.io.ByteOrderMark;
|
||||
import org.apache.commons.io.input.BOMInputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gdata.util.io.base.UnicodeReader;
|
||||
|
||||
public class IllegalCharacterUnitTest {
|
||||
|
||||
final String RESOURCE_FILE_NAME = "bom-file.txt";
|
||||
final InputStream ioStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream(RESOURCE_FILE_NAME);
|
||||
final String expected = "Hello world with BOM.";
|
||||
|
||||
@Test
|
||||
public void whenInputFileHasBOM_thenUseInputStream() throws IOException {
|
||||
String line;
|
||||
String actual = "";
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(ioStream))) {
|
||||
while ((line = br.readLine()) != null) {
|
||||
actual += line;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInputFileHasBOM_thenUseInputStreamWithReplace() throws IOException {
|
||||
String line;
|
||||
String actual = "";
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(Objects.requireNonNull(ioStream), StandardCharsets.UTF_8))) {
|
||||
while ((line = br.readLine()) != null) {
|
||||
actual += line.replace("\uFEFF", "");
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInputFileHasBOM_thenUseBOMInputStream() throws IOException {
|
||||
String line;
|
||||
String actual = "";
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(new BOMInputStream(ioStream, false, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE)))) {
|
||||
while ((line = br.readLine()) != null) {
|
||||
actual += line;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInputFileHasBOM_thenUseGoogleGdata() throws IOException {
|
||||
char[] actual = new char[21];
|
||||
|
||||
try (Reader r = new UnicodeReader(ioStream, null)) {
|
||||
r.read(actual);
|
||||
}
|
||||
|
||||
assertEquals(expected, String.valueOf(actual));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Hello world with BOM.
|
||||
Reference in New Issue
Block a user