Skip to content

Commit

Permalink
小修小改
Browse files Browse the repository at this point in the history
  • Loading branch information
lensferno committed Sep 19, 2021
1 parent fe53b33 commit 5154551
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 34 deletions.
19 changes: 7 additions & 12 deletions Dogename/src/main/java/me/lensferno/dogename/data/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ public class Data {
public static final int IGNORELIST_NAME_ONLY = 0;
public static final int IGNORELIST_NUMBER_ONLY = 1;
public static final int IGNORELIST_ALL = 2;
File dataFile;
SecureRandom secRandom = new SecureRandom();
Random random = new Random();

private final File dataFile = new File(FilePath.toSpecificPathForm("files/Namelist.data"));
private final SecureRandom secRandom = new SecureRandom();
private final Random random = new Random();

private List<String> nameList;
private final IgnoreList ignoreList = new IgnoreList();

public Data() {

dataFile = new File(FilePath.toSpecificPathForm("files/Namelist.data"));

try {

if (!dataFile.exists()) {
dataFile.getParentFile().mkdirs();
dataFile.createNewFile();
Expand All @@ -48,7 +46,6 @@ public Data() {
System.out.println("Failed to load data file.");
e.printStackTrace();
}

ignoreList.readIgnoreList();
}

Expand Down Expand Up @@ -90,9 +87,7 @@ public void importNameList(File path) {
System.out.println("error in import namelist:" + e);
e.printStackTrace();
}

}

}

public void makeMass() {
Expand Down Expand Up @@ -209,7 +204,7 @@ public int getNumberIgnoreListSize() {
return ignoreList.getNumberIgnoreListSize();
}

class IgnoreList {
static class IgnoreList {

private final File nameIgnoreFile = new File(FilePath.toSpecificPathForm("files/IgnoredNameList.data"));
private final File numbIgnoreFile = new File(FilePath.toSpecificPathForm("files/IgnoredNumberList.data"));
Expand Down Expand Up @@ -251,7 +246,7 @@ private void writeNumberIgnoreList() {
public void readIgnoreList() {
readNameIgnoreList();
readNumberIgnoreList();
System.out.println(String.format("There are %d names and %d numbers ignored", ignoreNameList.size(), ignoreNumberList.size()));
System.out.printf("There are %d names and %d numbers ignored", ignoreNameList.size(), ignoreNumberList.size());
}

private void readNameIgnoreList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public void loadHistory() {
File historyFile = new File(HISTORY_FILE);

try {

if (!historyFile.exists()) {
historyFile.getParentFile().mkdirs();
historyFile.createNewFile();
Expand Down Expand Up @@ -57,7 +56,6 @@ private void writeHistory() {
File historyFile = new File(HISTORY_FILE);

try {

if (!historyFile.exists()) {
historyFile.createNewFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ private void updateTokenStatus(int statusCode) {
if (netAvailable()) {
refreshToken();
}

if (checkTokenAvailable() != 0) {
tokenStatus = TOKEN_BAD;
}
Expand All @@ -55,19 +54,13 @@ public void init() {
if (tokenFile.exists()) {
loadToken();
updateTokenStatus(checkTokenAvailable());

} else {

if (netAvailable()) {

refreshToken();

updateTokenStatus(checkTokenAvailable());

} else {
tokenStatus = TOKEN_BAD;
}

}
}

Expand Down Expand Up @@ -98,17 +91,10 @@ private int checkTokenAvailable() {
return 0;
}


void fetchToken() {
try {
token = new Gson().fromJson(
NetworkUtil.getHtml(
TOKEN_API_URL
+ "?grant_type=client_credentials&client_id=" + API_KEY
+ "&client_secret=" + SEC_KEY,
true)
, Token.class);

NetworkUtil.getHtml(String.format("%s?grant_type=client_credentials&client_id=%s&client_secret=%s", TOKEN_API_URL, API_KEY, SEC_KEY), true), Token.class);
token.setExpTime();
} catch (Exception e) {
System.out.println("Error to get Token:" + e);
Expand All @@ -118,7 +104,6 @@ void fetchToken() {

private boolean netAvailable() {
try {

URL sourcesURL = new URL("http://www.baidu.com");
HttpURLConnection connection = (HttpURLConnection) sourcesURL.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36");
Expand All @@ -136,9 +121,8 @@ private boolean netAvailable() {
}

private void loadToken() {
ObjectInputStream ois;
try {
ois = new ObjectInputStream(new FileInputStream(tokenFile));
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(tokenFile));
this.token = (Token) ois.readObject();
ois.close();
} catch (Exception e) {
Expand All @@ -148,7 +132,6 @@ private void loadToken() {
}

private void writeToken() {

try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(tokenFile));
oos.writeObject(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class VoicePlayer {

Token token;
StreamPlayer streamPlayer = new StreamPlayer();
private VoiceConfig voiceConfig = null;
private final VoiceConfig voiceConfig;

public VoicePlayer(Token token, VoiceConfig voiceConfig) {
this.token = token;
Expand Down

0 comments on commit 5154551

Please sign in to comment.