mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-12-27 07:28:52 +00:00
fix: 去除重复代码
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
42dd115075
commit
975c50a32a
@ -1,8 +1,5 @@
|
||||
package pw.yumc.YumCore.config;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
@ -39,22 +36,6 @@ public class CommentConfig extends AbstractConfig {
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(final Reader reader) throws IOException, InvalidConfigurationException {
|
||||
final BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
try {
|
||||
String line;
|
||||
while ((line = input.readLine()) != null) {
|
||||
builder.append(line);
|
||||
builder.append(newLine);
|
||||
}
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
loadFromString(builder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromString(final String contents) throws InvalidConfigurationException {
|
||||
final String[] parts = contents.split(newLine);
|
||||
|
84
src/main/java/pw/yumc/YumCore/paste/PasteContent.java
Normal file
84
src/main/java/pw/yumc/YumCore/paste/PasteContent.java
Normal file
@ -0,0 +1,84 @@
|
||||
package pw.yumc.YumCore.paste;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据组装
|
||||
*
|
||||
* @since 2016年9月19日 下午3:40:49
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class PasteContent {
|
||||
private final static String errN = "异常名称: %s";
|
||||
private final static String errM = "异常说明: %s";
|
||||
private final static String errInfo = "简易错误信息如下:";
|
||||
private final static String errStackTrace = " 位于 %s.%s(%s:%s)";
|
||||
private final List<String> TEXT = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 添加文件
|
||||
*
|
||||
* @param file
|
||||
* 文件
|
||||
* @throws IOException
|
||||
* IO异常
|
||||
*/
|
||||
public void addFile(final File file) throws IOException {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("文件不得为Null!");
|
||||
}
|
||||
addLines(Files.readAllLines(file.toPath()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加行
|
||||
*
|
||||
* @param str
|
||||
* 行
|
||||
*/
|
||||
public void addLine(final String str) {
|
||||
this.TEXT.add(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加行
|
||||
*
|
||||
* @param str
|
||||
* 行
|
||||
*/
|
||||
public void addLines(final List<String> str) {
|
||||
this.TEXT.addAll(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加异常
|
||||
*
|
||||
* @param e
|
||||
* 异常
|
||||
*/
|
||||
public void addThrowable(final Throwable e) {
|
||||
Throwable temp = e;
|
||||
while (temp.getCause() != null) {
|
||||
temp = temp.getCause();
|
||||
}
|
||||
TEXT.add(String.format(errN, e.getClass().getName()));
|
||||
TEXT.add(String.format(errM, e.getMessage()));
|
||||
TEXT.add(errInfo);
|
||||
for (final StackTraceElement ste : e.getStackTrace()) {
|
||||
TEXT.add(String.format(errStackTrace, ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber() < 0 ? "未知" : ste.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder text = new StringBuilder();
|
||||
for (final String str : TEXT) {
|
||||
text.append(str + '\n');
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
}
|
25
src/main/java/pw/yumc/YumCore/paste/PasteFormat.java
Normal file
25
src/main/java/pw/yumc/YumCore/paste/PasteFormat.java
Normal file
@ -0,0 +1,25 @@
|
||||
package pw.yumc.YumCore.paste;
|
||||
|
||||
/**
|
||||
* 代码格式
|
||||
*
|
||||
* @since 2016年9月18日 下午7:00:15
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public enum PasteFormat {
|
||||
JAVA("java"),
|
||||
JAVASCRIPT("javascript"),
|
||||
HTML("html"),
|
||||
YAML("yaml");
|
||||
|
||||
String format;
|
||||
|
||||
private PasteFormat(final String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format;
|
||||
}
|
||||
}
|
@ -1,30 +1,25 @@
|
||||
package pw.yumc.YumCore.paste;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PasteXcode {
|
||||
private final String POST_URL = "http://paste.xcode.ro/";
|
||||
|
||||
public static void main(final String[] args) {
|
||||
final PasteXcode p = new PasteXcode();
|
||||
final Paste paste = new Paste();
|
||||
final PasteContent paste = new PasteContent();
|
||||
paste.addLine("异常提交测试!");
|
||||
paste.addThrowable(new Throwable());
|
||||
System.out.println(p.post(paste));;
|
||||
}
|
||||
|
||||
public String post(final PasteXcode.Paste content) {
|
||||
return post("YumCore", PasteXcode.Format.JAVA, content);
|
||||
public String post(final PasteContent content) {
|
||||
return post("YumCore", PasteFormat.JAVA, content);
|
||||
}
|
||||
|
||||
public String post(final String name, final PasteXcode.Format format, final PasteXcode.Paste content) {
|
||||
public String post(final String name, final PasteFormat format, final PasteContent content) {
|
||||
String result = "Failed to post!";
|
||||
try {
|
||||
final HttpURLConnection connection = (HttpURLConnection) new URL(POST_URL).openConnection();
|
||||
@ -47,66 +42,4 @@ public class PasteXcode {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public enum Format {
|
||||
JAVA("java"),
|
||||
JAVASCRIPT("javascript"),
|
||||
HTML("html");
|
||||
|
||||
String format;
|
||||
|
||||
private Format(final String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Paste {
|
||||
private final static String errN = "异常名称: %s";
|
||||
private final static String errM = "异常说明: %s";
|
||||
private final static String errInfo = "简易错误信息如下:";
|
||||
private final static String errStackTrace = " 位于 %s.%s(%s:%s)";
|
||||
private final List<String> TEXT = new ArrayList<>();
|
||||
|
||||
public void addFile(final File file) throws IOException {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("文件不得为Null!");
|
||||
}
|
||||
addLines(Files.readAllLines(file.toPath()));
|
||||
}
|
||||
|
||||
public void addLine(final String str) {
|
||||
this.TEXT.add(str);
|
||||
}
|
||||
|
||||
public void addLines(final List<String> str) {
|
||||
this.TEXT.addAll(str);
|
||||
}
|
||||
|
||||
public void addThrowable(final Throwable e) {
|
||||
Throwable temp = e;
|
||||
while (temp.getCause() != null) {
|
||||
temp = temp.getCause();
|
||||
}
|
||||
TEXT.add(String.format(errN, e.getClass().getName()));
|
||||
TEXT.add(String.format(errM, e.getMessage()));
|
||||
TEXT.add(errInfo);
|
||||
for (final StackTraceElement ste : e.getStackTrace()) {
|
||||
TEXT.add(String.format(errStackTrace, ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber() < 0 ? "未知" : ste.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder text = new StringBuilder();
|
||||
for (final String str : TEXT) {
|
||||
text.append(str + '\n');
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,11 @@
|
||||
package pw.yumc.YumCore.paste;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Pastebin {
|
||||
private final String POST_URL = "http://pastebin.com/api/api_post.php";
|
||||
@ -26,17 +21,17 @@ public class Pastebin {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
final Pastebin p = new Pastebin();
|
||||
final Paste paste = new Paste();
|
||||
final PasteContent paste = new PasteContent();
|
||||
paste.addLine("异常提交测试!");
|
||||
paste.addThrowable(new Throwable());
|
||||
System.out.println(p.post(paste));;
|
||||
}
|
||||
|
||||
public String post(final Pastebin.Paste content) {
|
||||
return post("", Pastebin.Format.JAVA, Pastebin.Private.UNLISTED, content);
|
||||
public String post(final PasteContent content) {
|
||||
return post("", PasteFormat.JAVA, Pastebin.Private.UNLISTED, content);
|
||||
}
|
||||
|
||||
public String post(final String name, final Pastebin.Format format, final Pastebin.Private level, final Pastebin.Paste content) {
|
||||
public String post(final String name, final PasteFormat format, final Pastebin.Private level, final PasteContent content) {
|
||||
String result = "Failed to post!";
|
||||
try {
|
||||
final HttpURLConnection connection = (HttpURLConnection) new URL(POST_URL).openConnection();
|
||||
@ -82,67 +77,6 @@ public class Pastebin {
|
||||
return result;
|
||||
}
|
||||
|
||||
public enum Format {
|
||||
JAVA("java"),
|
||||
YAML("yaml");
|
||||
|
||||
String format;
|
||||
|
||||
private Format(final String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Paste {
|
||||
private final static String errN = "异常名称: %s";
|
||||
private final static String errM = "异常说明: %s";
|
||||
private final static String errInfo = "简易错误信息如下:";
|
||||
private final static String errStackTrace = " 位于 %s.%s(%s:%s)";
|
||||
private final List<String> TEXT = new ArrayList<>();
|
||||
|
||||
public void addFile(final File file) throws IOException {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("文件不得为Null!");
|
||||
}
|
||||
addLines(Files.readAllLines(file.toPath()));
|
||||
}
|
||||
|
||||
public void addLine(final String str) {
|
||||
this.TEXT.add(str);
|
||||
}
|
||||
|
||||
public void addLines(final List<String> str) {
|
||||
this.TEXT.addAll(str);
|
||||
}
|
||||
|
||||
public void addThrowable(final Throwable e) {
|
||||
Throwable temp = e;
|
||||
while (temp.getCause() != null) {
|
||||
temp = temp.getCause();
|
||||
}
|
||||
TEXT.add(String.format(errN, e.getClass().getName()));
|
||||
TEXT.add(String.format(errM, e.getMessage()));
|
||||
TEXT.add(errInfo);
|
||||
for (final StackTraceElement ste : e.getStackTrace()) {
|
||||
TEXT.add(String.format(errStackTrace, ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber() < 0 ? "未知" : ste.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder text = new StringBuilder();
|
||||
for (final String str : TEXT) {
|
||||
text.append(str + '\n');
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Private {
|
||||
PUBLIC(0),
|
||||
UNLISTED(1),
|
||||
|
@ -1,16 +1,10 @@
|
||||
package pw.yumc.YumCore.paste;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
@ -28,11 +22,21 @@ public class StickyNotes {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
final StickyNotes p = new StickyNotes();
|
||||
final Paste paste = new Paste();
|
||||
final PasteContent paste = new PasteContent();
|
||||
paste.addLine("异常提交测试!");
|
||||
paste.addThrowable(new Throwable());
|
||||
System.out.println(p.post(StickyNotes.Expire.HalfHour, paste));
|
||||
;
|
||||
System.out.println(p.post(StickyNotes.Expire.HalfHour, paste));;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传数据
|
||||
*
|
||||
* @param content
|
||||
* 内容
|
||||
* @return 地址
|
||||
*/
|
||||
public String post(final PasteContent content) {
|
||||
return post("YumCore-" + System.currentTimeMillis(), PasteFormat.JAVA, StickyNotes.Expire.Never, content);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,19 +48,8 @@ public class StickyNotes {
|
||||
* 内容
|
||||
* @return 地址
|
||||
*/
|
||||
public String post(final StickyNotes.Expire expire, final StickyNotes.Paste content) {
|
||||
return post("YumCore-" + System.currentTimeMillis(), StickyNotes.Format.JAVA, expire, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传数据
|
||||
*
|
||||
* @param content
|
||||
* 内容
|
||||
* @return 地址
|
||||
*/
|
||||
public String post(final StickyNotes.Paste content) {
|
||||
return post("YumCore-" + System.currentTimeMillis(), StickyNotes.Format.JAVA, StickyNotes.Expire.Never, content);
|
||||
public String post(final StickyNotes.Expire expire, final PasteContent content) {
|
||||
return post("YumCore-" + System.currentTimeMillis(), PasteFormat.JAVA, expire, content);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +65,7 @@ public class StickyNotes {
|
||||
* 内容
|
||||
* @return 地址
|
||||
*/
|
||||
public String post(final String title, final StickyNotes.Format format, final StickyNotes.Expire expire, final StickyNotes.Paste content) {
|
||||
public String post(final String title, final PasteFormat format, final StickyNotes.Expire expire, final PasteContent content) {
|
||||
return post(title, format.toString(), expire.getExpire(), content.toString());
|
||||
}
|
||||
|
||||
@ -149,79 +142,4 @@ public class StickyNotes {
|
||||
return expire;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码格式
|
||||
*
|
||||
* @since 2016年9月18日 下午7:00:15
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public enum Format {
|
||||
JAVA("java"),
|
||||
JAVASCRIPT("javascript"),
|
||||
HTML("html"),
|
||||
YAML("yaml");
|
||||
|
||||
String format;
|
||||
|
||||
private Format(final String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据组装
|
||||
*
|
||||
* @since 2016年9月18日 下午7:00:21
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public static class Paste {
|
||||
private final static String errN = "异常名称: %s";
|
||||
private final static String errM = "异常说明: %s";
|
||||
private final static String errInfo = "简易错误信息如下:";
|
||||
private final static String errStackTrace = " 位于 %s.%s(%s:%s)";
|
||||
private final List<String> TEXT = new ArrayList<>();
|
||||
|
||||
public void addFile(final File file) throws IOException {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("文件不得为Null!");
|
||||
}
|
||||
addLines(Files.readAllLines(file.toPath(), Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
public void addLine(final String str) {
|
||||
this.TEXT.add(str);
|
||||
}
|
||||
|
||||
public void addLines(final List<String> str) {
|
||||
this.TEXT.addAll(str);
|
||||
}
|
||||
|
||||
public void addThrowable(final Throwable e) {
|
||||
Throwable temp = e;
|
||||
while (temp.getCause() != null) {
|
||||
temp = temp.getCause();
|
||||
}
|
||||
TEXT.add(String.format(errN, e.getClass().getName()));
|
||||
TEXT.add(String.format(errM, e.getMessage()));
|
||||
TEXT.add(errInfo);
|
||||
for (final StackTraceElement ste : e.getStackTrace()) {
|
||||
TEXT.add(String.format(errStackTrace, ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber() < 0 ? "未知" : ste.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder text = new StringBuilder();
|
||||
for (final String str : TEXT) {
|
||||
text.append(str + '\n');
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user