LunaChat v3.0.3 : Clickable chat message (WIP)
このコミットが含まれているのは:
1 親
0466653e89
コミット
e2eea8798d
22ファイル変更
+756
-457
検索条件に一致するファイルはありません
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* チャットのフォーマットを作成するユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChatFormatter {
|
||||
|
||||
private static ChatFormatter instance;
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
private static final String JOIN_COMMAND_TEMPLATE = "/lunachat join %s";
|
||||
private static final String TELL_COMMAND_TEMPLATE = "/tell %s ";
|
||||
|
||||
private ChatFormatter() {
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @param channel チャンネル
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
public static String replaceKeywordsForChannel(String format, @Nullable ChannelMember member, @NotNull Channel channel) {
|
||||
|
||||
if ( instance == null ) {
|
||||
instance = new ChatFormatter();
|
||||
}
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
KeywordReplacer msg = new KeywordReplacer(format);
|
||||
|
||||
// テンプレートのキーワードを、まず最初に置き換える
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( msg.contains(key) ) {
|
||||
if ( api.getTemplate("" + i) != null ) {
|
||||
msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg.replace("%ch", String.format(
|
||||
"<type=RUN_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
channel.getName(),
|
||||
Messages.hoverChannelName(channel.getName()),
|
||||
String.format(JOIN_COMMAND_TEMPLATE, channel.getName())));
|
||||
//msg.replace("%msg", message);
|
||||
msg.replace("%color", channel.getColorCode());
|
||||
if ( channel.getPrivateMessageTo() != null ) {
|
||||
// msg.replace("%to", channel.getPrivateMessageTo().getDisplayName());
|
||||
msg.replace("%to", String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
channel.getPrivateMessageTo().getDisplayName(),
|
||||
Messages.hoverPlayerName(channel.getPrivateMessageTo().getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, channel.getPrivateMessageTo().getName())));
|
||||
msg.replace("%recieverserver", channel.getPrivateMessageTo().getServerName());
|
||||
} else {
|
||||
msg.replace("%to", "");
|
||||
msg.replace("%recieverserver", "");
|
||||
}
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg.replace("%date", instance.dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg.replace("%time", instance.timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( member != null ) {
|
||||
|
||||
String playerPMPlaceHolder = String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getDisplayName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName()));
|
||||
msg.replace("%displayname", playerPMPlaceHolder);
|
||||
msg.replace("%username", playerPMPlaceHolder);
|
||||
msg.replace("%player", String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName())));
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg.replace("%prefix", member.getPrefix());
|
||||
msg.replace("%suffix", member.getSuffix());
|
||||
}
|
||||
|
||||
msg.replace("%world", member.getWorldName());
|
||||
msg.replace("%server", member.getServerName());
|
||||
|
||||
} else {
|
||||
msg.replace("%displayname", "");
|
||||
msg.replace("%username", "");
|
||||
msg.replace("%player", "");
|
||||
msg.replace("%prefix", "");
|
||||
msg.replace("%suffix", "");
|
||||
msg.replace("%world", "");
|
||||
msg.replace("%server", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットのフォーマット設定のキーワードを置き換えして返す
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @return キーワード置き換え済みの文字列
|
||||
*/
|
||||
public static String replaceKeywordsForEvent(String format, @NotNull ChannelMember member) {
|
||||
|
||||
if ( instance == null ) {
|
||||
instance = new ChatFormatter();
|
||||
}
|
||||
|
||||
KeywordReplacer msg = new KeywordReplacer(format);
|
||||
|
||||
String playerPMPlaceHolder = String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getDisplayName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName()));
|
||||
msg.replace("%displayname", playerPMPlaceHolder);
|
||||
msg.replace("%username", playerPMPlaceHolder);
|
||||
msg.replace("%player", String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName())));
|
||||
|
||||
// msg.replace("%msg", "%2$s");
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg.replace("%date", instance.dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg.replace("%time", instance.timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg.replace("%prefix", member.getPrefix());
|
||||
msg.replace("%suffix", member.getSuffix());
|
||||
}
|
||||
|
||||
msg.replace("%world", member.getWorldName());
|
||||
msg.replace("%server", member.getServerName());
|
||||
|
||||
return Utility.replaceColorCode(msg.toString());
|
||||
}
|
||||
|
||||
|
||||
public static BaseComponent[] replaceTextComponent(String src) {
|
||||
|
||||
List<BaseComponent> components = new ArrayList<>();
|
||||
Pattern pattern = Pattern.compile(
|
||||
"<type=(SUGGEST_COMMAND|RUN_COMMAND) text=\"([^\"]*)\" hover=\"([^\"]*)\" command=\"([^\"]*)\">");
|
||||
Matcher matcher = pattern.matcher(src);
|
||||
int lastIndex = 0;
|
||||
|
||||
while ( matcher.find() ) {
|
||||
|
||||
// マッチする箇所までの文字列を取得する
|
||||
if ( lastIndex < matcher.start() ) {
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(src.substring(lastIndex, matcher.start())) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
// マッチした箇所の文字列を解析して追加する
|
||||
String type = matcher.group(1);
|
||||
String text = matcher.group(2);
|
||||
String hover = matcher.group(3);
|
||||
String command = matcher.group(4);
|
||||
TextComponent tc = new TextComponent(text);
|
||||
if ( !hover.isEmpty() ) {
|
||||
tc.setHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create()));
|
||||
}
|
||||
if ( type.equals("RUN_COMMAND") ) {
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
||||
} else {
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||
}
|
||||
components.add(tc);
|
||||
|
||||
lastIndex = matcher.end() + 1;
|
||||
}
|
||||
|
||||
if ( lastIndex < src.length() - 1 ) {
|
||||
// 残りの部分の文字列を取得する
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(src.substring(lastIndex)) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
BaseComponent[] result = new BaseComponent[components.size()];
|
||||
components.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* チャットのフォーマットを作成するユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ClickableFormat {
|
||||
|
||||
private static final String JOIN_COMMAND_TEMPLATE = "/lunachat join %s";
|
||||
private static final String TELL_COMMAND_TEMPLATE = "/tell %s";
|
||||
|
||||
private static final String PLACEHOLDER_RUN_COMMAND =
|
||||
"<type=RUN_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">";
|
||||
private static final String PLACEHOLDER_SUGGEST_COMMAND =
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">";
|
||||
private static final String PLACEHOLDER_PATTERN =
|
||||
"<type=(SUGGEST_COMMAND|RUN_COMMAND) text=\"([^\"]*)\" hover=\"([^\"]*)\" command=\"([^\"]*)\">";
|
||||
|
||||
private KeywordReplacer message;
|
||||
|
||||
private ClickableFormat(KeywordReplacer message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
public static ClickableFormat makeFormat(String format, @Nullable ChannelMember member) {
|
||||
return makeFormat(format, member, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @param channel チャンネル
|
||||
* @param withPlayerLink プレイヤー名の箇所にクリック可能なプレースホルダーを挿入するか
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
public static ClickableFormat makeFormat(String format,
|
||||
@Nullable ChannelMember member, @Nullable Channel channel, boolean withPlayerLink) {
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
KeywordReplacer msg = new KeywordReplacer(format);
|
||||
|
||||
//msg.replace("%msg", message);
|
||||
|
||||
if ( channel != null ) {
|
||||
|
||||
// テンプレートのキーワードを、まず最初に置き換える
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( msg.contains(key) ) {
|
||||
if ( api.getTemplate("" + i) != null ) {
|
||||
msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネル関連のキーワード置き換え
|
||||
msg.replace("%ch", String.format(
|
||||
PLACEHOLDER_RUN_COMMAND,
|
||||
channel.getName(),
|
||||
Messages.hoverChannelName(channel.getName()),
|
||||
String.format(JOIN_COMMAND_TEMPLATE, channel.getName())));
|
||||
msg.replace("%color", channel.getColorCode());
|
||||
if ( channel.getPrivateMessageTo() != null ) {
|
||||
msg.replace("%to", String.format(
|
||||
PLACEHOLDER_SUGGEST_COMMAND,
|
||||
channel.getPrivateMessageTo().getDisplayName(),
|
||||
Messages.hoverPlayerName(channel.getPrivateMessageTo().getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, channel.getPrivateMessageTo().getName())));
|
||||
msg.replace("%recieverserver", channel.getPrivateMessageTo().getServerName());
|
||||
}
|
||||
}
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( member != null ) {
|
||||
|
||||
// ChannelMember関連のキーワード置き換え
|
||||
if ( withPlayerLink ) {
|
||||
String playerPMPlaceHolder = String.format(
|
||||
PLACEHOLDER_SUGGEST_COMMAND,
|
||||
member.getDisplayName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName()));
|
||||
msg.replace("%displayname", playerPMPlaceHolder);
|
||||
msg.replace("%username", playerPMPlaceHolder);
|
||||
msg.replace("%player", String.format(
|
||||
PLACEHOLDER_SUGGEST_COMMAND,
|
||||
member.getName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName())));
|
||||
} else {
|
||||
msg.replace("%displayname", member.getDisplayName());
|
||||
msg.replace("%username", member.getDisplayName());
|
||||
msg.replace("%player", member.getName());
|
||||
}
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg.replace("%prefix", member.getPrefix());
|
||||
msg.replace("%suffix", member.getSuffix());
|
||||
}
|
||||
|
||||
msg.replace("%world", member.getWorldName());
|
||||
msg.replace("%server", member.getServerName());
|
||||
}
|
||||
|
||||
return new ClickableFormat(msg);
|
||||
}
|
||||
|
||||
|
||||
public BaseComponent[] makeTextComponent() {
|
||||
|
||||
message.translateColorCode();
|
||||
|
||||
List<BaseComponent> components = new ArrayList<>();
|
||||
Matcher matcher = Pattern.compile(PLACEHOLDER_PATTERN).matcher(message.getStringBuilder());
|
||||
int lastIndex = 0;
|
||||
|
||||
while ( matcher.find() ) {
|
||||
|
||||
// マッチする箇所までの文字列を取得する
|
||||
if ( lastIndex < matcher.start() ) {
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(message.substring(lastIndex, matcher.start())) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
// マッチした箇所の文字列を解析して追加する
|
||||
String type = matcher.group(1);
|
||||
String text = matcher.group(2);
|
||||
String hover = matcher.group(3);
|
||||
String command = matcher.group(4);
|
||||
TextComponent tc = new TextComponent(text);
|
||||
if ( !hover.isEmpty() ) {
|
||||
tc.setHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create()));
|
||||
}
|
||||
if ( type.equals("RUN_COMMAND") ) {
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
||||
} else { // type.equals("SUGGEST_COMMAND")
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||
}
|
||||
components.add(tc);
|
||||
|
||||
lastIndex = matcher.end();
|
||||
}
|
||||
|
||||
if ( lastIndex < message.length() - 1 ) {
|
||||
// 残りの部分の文字列を取得する
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(message.substring(lastIndex)) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
BaseComponent[] result = new BaseComponent[components.size()];
|
||||
components.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toLegacyText() {
|
||||
|
||||
StringBuilder msg = new StringBuilder(message.toString());
|
||||
Matcher matcher = Pattern.compile(PLACEHOLDER_PATTERN).matcher(msg);
|
||||
|
||||
while ( matcher.find(0) ) {
|
||||
String text = matcher.group(2);
|
||||
msg.replace(matcher.start(), matcher.end(), text);
|
||||
}
|
||||
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
public void replace(String keyword, String value) {
|
||||
message.replace(keyword, value);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 文字列のキーワード置き換えを行うユーティリティクラス
|
||||
* @author ucchy
|
||||
@@ -22,7 +24,7 @@ public class KeywordReplacer {
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列keywordえを、文字列valueに置き替える
|
||||
* 文字列keywordを、文字列valueに置き換える
|
||||
* @param keyword キーワード
|
||||
* @param value 値
|
||||
*/
|
||||
@@ -33,6 +35,22 @@ public class KeywordReplacer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正規表現regexに一致する箇所を、文字列valueに置き換える
|
||||
* @param regex 正規表現
|
||||
* @param value 値
|
||||
*/
|
||||
public void replaceRegex(String regex, String value) {
|
||||
str = new StringBuilder(Pattern.compile(regex).matcher(str).replaceAll(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列内のカラーコード候補(&a)を、カラーコード(§a)に置き換えする
|
||||
*/
|
||||
public void translateColorCode() {
|
||||
str = new StringBuilder(Utility.replaceColorCode(str.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された文字列が含まれているかどうかを判定する
|
||||
* @param keyword キーワード
|
||||
@@ -51,4 +69,24 @@ public class KeywordReplacer {
|
||||
public String toString() {
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列をStringBuilderのまま取得する
|
||||
* @return StringBuilder
|
||||
*/
|
||||
public StringBuilder getStringBuilder() {
|
||||
return str;
|
||||
}
|
||||
|
||||
public String substring(int start) {
|
||||
return str.substring(start);
|
||||
}
|
||||
|
||||
public String substring(int start, int end) {
|
||||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return str.length();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import java.util.zip.ZipEntry;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* ユーティリティクラス
|
||||
@@ -41,34 +42,46 @@ public class Utility {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
try ( JarFile jar = new JarFile(jarFile) ) {
|
||||
ZipEntry zipEntry = jar.getEntry(sourceFilePath);
|
||||
InputStream is = jar.getInputStream(zipEntry);
|
||||
if ( jarFile.isDirectory() ) {
|
||||
File file = new File(jarFile, sourceFilePath);
|
||||
|
||||
try ( FileOutputStream fos = new FileOutputStream(targetFile) ) {
|
||||
try {
|
||||
Files.copy(file, targetFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (isBinary) {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
} else {
|
||||
|
||||
} else {
|
||||
try ( JarFile jar = new JarFile(jarFile) ) {
|
||||
ZipEntry zipEntry = jar.getEntry(sourceFilePath);
|
||||
InputStream is = jar.getInputStream(zipEntry);
|
||||
|
||||
try ( BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")) ) {
|
||||
try ( FileOutputStream fos = new FileOutputStream(targetFile) ) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
if (isBinary) {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
try ( BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")) ) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +122,7 @@ public class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列に含まれているカラーコード候補(&a)を除去して返す
|
||||
* 文字列に含まれているカラーコード候補(&aや#99AABB)を除去して返す
|
||||
* @param source 置き換え元の文字列
|
||||
* @return 置き換え後の文字列
|
||||
*/
|
||||
@@ -130,7 +143,7 @@ public class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* カラーコード候補(&a)かどうかを判断する
|
||||
* カラーコード候補(&aや#99AABB)かどうかを判断する
|
||||
* @param color カラーコード候補
|
||||
* @return カラーコード候補かどうか
|
||||
*/
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする