-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from aodn/encoding-right
Fix to ingest when record contains nonvalid chars
- Loading branch information
Showing
4 changed files
with
84 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package au.org.aodn.esindexer.utils; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class StringUtil { | ||
// Static method to convert to UTF-8 String | ||
public static String toUTF8String(String input) { | ||
return new String(input.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import au.org.aodn.esindexer.utils.StringUtil; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class StringUtilTest { | ||
@Test | ||
public void testToUTF8String_withAsciiString() { | ||
String asciiString = "Hello World"; | ||
String result = StringUtil.toUTF8String(asciiString); | ||
assertEquals(asciiString, result, "The UTF-8 conversion of an ASCII string should not change the string"); | ||
} | ||
|
||
@Test | ||
public void testToUTF8String_withFrenchCharacters() { | ||
String frenchString = "Bonjour le monde! Ça va?"; | ||
String result = StringUtil.toUTF8String(frenchString); | ||
assertEquals(frenchString, result, "The UTF-8 conversion of a string with French characters should not change the string"); | ||
} | ||
|
||
@Test | ||
public void testToUTF8String_withDegreeSign() { | ||
String stringWithDegreeSign = "Temperature: 25°C"; | ||
String result = StringUtil.toUTF8String(stringWithDegreeSign); | ||
assertEquals(stringWithDegreeSign, result, "The UTF-8 conversion of a string with a degree sign should not change the string"); | ||
} | ||
} |