Skip to content

Commit

Permalink
[totd] simplify reading TOTD file into string (#6586)
Browse files Browse the repository at this point in the history
  • Loading branch information
grimreaper authored Sep 20, 2021
1 parent 2152385 commit c576fd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
21 changes: 4 additions & 17 deletions code/src/java/pcgen/gui2/tools/TipOfTheDayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
*/
package pcgen.gui2.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
Expand Down Expand Up @@ -119,19 +116,9 @@ public synchronized void loadTips()

private void loadTipFile(String tipsFilePath) throws IOException
{
final File tipsFile = new File(tipsFilePath);
String fileAsString = Files.readString(Path.of(tipsFilePath));

final char[] inputLine;
try (Reader tipsReader = new BufferedReader(new InputStreamReader(new FileInputStream(tipsFile),
StandardCharsets.UTF_8
)))
{
final int length = (int) tipsFile.length();
inputLine = new char[length];
tipsReader.read(inputLine, 0, length);
}

final StringTokenizer aTok = new StringTokenizer(new String(inputLine), "\r\n", false);
final StringTokenizer aTok = new StringTokenizer(fileAsString, "\r\n", false);

while (aTok.hasMoreTokens())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
public class LookupToken extends AbstractToken implements CDOMPrimaryToken<KitGear>
{

/**
* Gets the name of the tag this class will parse.
*
Expand Down

0 comments on commit c576fd9

Please sign in to comment.