Compare commits
13 Commits
2.0.0.alph
...
2.0.0.beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b2fd9965b | ||
|
|
0938635eb2 | ||
|
|
a4a186751e | ||
|
|
ea5169b5c5 | ||
|
|
01bd195847 | ||
|
|
a72c26a935 | ||
|
|
a9900d9bfa | ||
|
|
6896401d2d | ||
|
|
886f01c9f3 | ||
|
|
59c9251d70 | ||
|
|
fad5f010d2 | ||
|
|
737c4a92b9 | ||
|
|
d3e8675948 |
@@ -192,7 +192,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
}
|
||||
int max = 0;
|
||||
if (ss != null && sb != null) {
|
||||
Collections.sort(ss, (AbstractMap.SimpleEntry<String, String[]> o1, AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey()));
|
||||
ss.sort((AbstractMap.SimpleEntry<String, String[]> o1, AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey()));
|
||||
for (AbstractMap.SimpleEntry<String, String[]> as : ss) {
|
||||
if (as.getKey().length() > max) max = as.getKey().length();
|
||||
}
|
||||
@@ -340,7 +340,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
}
|
||||
//输出信息
|
||||
if (ss != null && !ss.isEmpty() && sb != null) {
|
||||
Collections.sort(ss, (AbstractMap.SimpleEntry<String, String[]> o1, AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey()));
|
||||
ss.sort((AbstractMap.SimpleEntry<String, String[]> o1, AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey()));
|
||||
int max = 0;
|
||||
for (AbstractMap.SimpleEntry<String, String[]> as : ss) {
|
||||
if (as.getKey().length() > max) max = as.getKey().length();
|
||||
|
||||
@@ -498,7 +498,7 @@ public abstract class NodeServer {
|
||||
}
|
||||
//----------------- init -----------------
|
||||
List<Service> swlist = new ArrayList<>(localServices);
|
||||
Collections.sort(swlist, (o1, o2) -> {
|
||||
swlist.sort((o1, o2) -> {
|
||||
Priority p1 = o1.getClass().getAnnotation(Priority.class);
|
||||
Priority p2 = o2.getClass().getAnnotation(Priority.class);
|
||||
int v = (p2 == null ? 0 : p2.value()) - (p1 == null ? 0 : p1.value());
|
||||
|
||||
@@ -89,4 +89,9 @@ public final class ConvertColumnEntry {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConvertColumnEntry{" + "index=" + index + ", name=" + name + ", ignore=" + ignore + ", convertType=" + convertType + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -251,8 +251,8 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
}
|
||||
for (ConvertColumn ref : ccs) {
|
||||
if (ref.type().contains(ct)) {
|
||||
String realName = ref.name().isEmpty() ? fieldName : ref.name();
|
||||
if (onlyColumns != null && fieldName != null) {
|
||||
String realName = ref.name().isEmpty() ? fieldName : ref.name();
|
||||
if (!onlyColumns.contains(realName)) return new ConvertColumnEntry(realName, true);
|
||||
}
|
||||
ConvertColumnEntry entry = new ConvertColumnEntry(ref);
|
||||
@@ -260,7 +260,10 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
entry.setIgnore(false);
|
||||
return entry;
|
||||
}
|
||||
if (skipIgnores.isEmpty()) return entry;
|
||||
if (skipIgnores.isEmpty()) {
|
||||
if (onlyColumns != null && realName != null && onlyColumns.contains(realName)) entry.setIgnore(false);
|
||||
return entry;
|
||||
}
|
||||
if (skipIgnores.contains(((Member) element).getDeclaringClass())) entry.setIgnore(false);
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
classLoader.addURL(url);
|
||||
}
|
||||
List<URL> list = new ArrayList<>(set);
|
||||
Collections.sort(list, (URL o1, URL o2) -> o1.getFile().compareTo(o2.getFile()));
|
||||
list.sort((URL o1, URL o2) -> o1.getFile().compareTo(o2.getFile()));
|
||||
return list.toArray(new URL[list.size()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
logger.log(Level.WARNING, "init HttpRender(" + renderType + ") error", e);
|
||||
}
|
||||
}
|
||||
Collections.sort(renders, (o1, o2) -> o1.getType().isAssignableFrom(o2.getType()) ? 1 : -1);
|
||||
renders.sort((o1, o2) -> o1.getType().isAssignableFrom(o2.getType()) ? 1 : -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ class WebSocketRunner implements Runnable {
|
||||
}
|
||||
} else if (packet.type == FrameType.PONG) {
|
||||
try {
|
||||
if (debug) context.getLogger().log(Level.FINEST, "WebSocketRunner onMessage by PONG FrameType : " + packet);
|
||||
//if (debug) context.getLogger().log(Level.FINEST, "WebSocketRunner onMessage by PONG FrameType : " + packet);
|
||||
webSocket.onPong((byte[]) packet.receiveMessage);
|
||||
} catch (Exception e) {
|
||||
context.getLogger().log(Level.SEVERE, "WebSocket onPong error (" + packet + ")", e);
|
||||
|
||||
@@ -54,11 +54,11 @@ public class RetResult<T> {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public static <T> RetResult<T> success() {
|
||||
return new RetResult<>();
|
||||
public static RetResult success() {
|
||||
return new RetResult();
|
||||
}
|
||||
|
||||
public static <V, T> RetResult<T> success(V result) {
|
||||
public static <T> RetResult<T> success(T result) {
|
||||
return new RetResult().result(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = readPool.poll();
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final Statement stmt = conn.createStatement();
|
||||
ResultSet set = stmt.executeQuery(sql);
|
||||
final Map map = new HashMap<>();
|
||||
@@ -382,7 +382,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = readPool.poll();
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final Statement stmt = conn.createStatement();
|
||||
Number rs = defVal;
|
||||
ResultSet set = stmt.executeQuery(sql);
|
||||
@@ -407,7 +407,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = readPool.poll();
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final Statement stmt = conn.createStatement();
|
||||
Map<K, N> rs = new LinkedHashMap<>();
|
||||
ResultSet set = stmt.executeQuery(sql);
|
||||
@@ -433,7 +433,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = readPool.poll();
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ps.setFetchSize(1);
|
||||
final ResultSet set = ps.executeQuery();
|
||||
@@ -456,7 +456,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = readPool.poll();
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final Attribute<T, Serializable> attr = info.getAttribute(column);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ps.setFetchSize(1);
|
||||
@@ -483,7 +483,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = readPool.poll();
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
final ResultSet set = ps.executeQuery();
|
||||
boolean rs = set.next() ? (set.getInt(1) > 0) : false;
|
||||
@@ -502,11 +502,11 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> CompletableFuture<Sheet<T>> querySheetDB(EntityInfo<T> info, boolean needtotal, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||
protected <T> CompletableFuture<Sheet<T>> querySheetDB(EntityInfo<T> info, final boolean readcache, boolean needtotal, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = readPool.poll();
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final SelectColumn sels = selects;
|
||||
final List<T> list = new ArrayList();
|
||||
final Map<Class, String> joinTabalis = node == null ? null : node.getJoinTabalis();
|
||||
@@ -516,7 +516,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
if ("mysql".equals(dbtype) || "postgresql".equals(dbtype)) {
|
||||
final String listsql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join)
|
||||
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + createSQLOrderby(info, flipper) + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset()));
|
||||
if (info.isLoggable(logger, Level.FINEST, listsql)) {
|
||||
if (readcache && info.isLoggable(logger, Level.FINEST, listsql)) {
|
||||
logger.finest(info.getType().getSimpleName() + " query sql=" + listsql);
|
||||
}
|
||||
PreparedStatement ps = conn.prepareStatement(listsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
@@ -529,7 +529,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
long total = list.size();
|
||||
if (needtotal) {
|
||||
final String countsql = "SELECT COUNT(*) FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||
if (info.isLoggable(logger, Level.FINEST, countsql)) {
|
||||
if (readcache && info.isLoggable(logger, Level.FINEST, countsql)) {
|
||||
logger.finest(info.getType().getSimpleName() + " query countsql=" + countsql);
|
||||
}
|
||||
ps = conn.prepareStatement(countsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
@@ -542,10 +542,10 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
}
|
||||
final String sql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join)
|
||||
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + info.createSQLOrderby(flipper);
|
||||
if (info.isLoggable(logger, Level.FINEST, sql)) {
|
||||
if (readcache && info.isLoggable(logger, Level.FINEST, sql)) {
|
||||
logger.finest(info.getType().getSimpleName() + " query sql=" + sql + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset())));
|
||||
}
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
if (flipper != null && flipper.getLimit() > 0) ps.setFetchSize(flipper.getLimit());
|
||||
final ResultSet set = ps.executeQuery();
|
||||
@@ -635,7 +635,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
||||
final Connection conn = readPool.poll();
|
||||
try {
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("direct query sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
//conn.setReadOnly(true);
|
||||
final Statement statement = conn.createStatement();
|
||||
//final PreparedStatement statement = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
final ResultSet set = statement.executeQuery(sql);// ps.executeQuery();
|
||||
|
||||
@@ -144,7 +144,7 @@ public class DataMemorySource extends DataSqlSource<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> CompletableFuture<Sheet<T>> querySheetDB(EntityInfo<T> info, boolean needtotal, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||
protected <T> CompletableFuture<Sheet<T>> querySheetDB(EntityInfo<T> info, final boolean readcache, boolean needtotal, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||
return CompletableFuture.completedFuture(new Sheet<>());
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
||||
protected abstract <T> CompletableFuture<Boolean> existsDB(final EntityInfo<T> info, final String sql, final boolean onlypk);
|
||||
|
||||
//查询一页数据
|
||||
protected abstract <T> CompletableFuture<Sheet<T>> querySheetDB(final EntityInfo<T> info, final boolean needtotal, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
||||
protected abstract <T> CompletableFuture<Sheet<T>> querySheetDB(final EntityInfo<T> info, final boolean readcache, final boolean needtotal, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
||||
|
||||
protected <T> T getEntityValue(EntityInfo<T> info, final SelectColumn sels, final ResultSet set) throws SQLException {
|
||||
return info.getEntityValue(sels, set);
|
||||
@@ -284,6 +284,21 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
||||
return null;
|
||||
}
|
||||
|
||||
protected <T> String formatValueToString(final EntityInfo<T> info, Object value) {
|
||||
final String dbtype = this.readPool.getDbtype();
|
||||
if ("mysql".equals(dbtype)) {
|
||||
if (value == null) return null;
|
||||
if (value instanceof CharSequence) {
|
||||
return new StringBuilder().append('\'').append(value.toString().replace("\\", "\\\\").replace("'", "\\'")).append('\'').toString();
|
||||
} else if (!(value instanceof Number) && !(value instanceof java.util.Date)
|
||||
&& !value.getClass().getName().startsWith("java.sql.") && !value.getClass().getName().startsWith("java.time.")) {
|
||||
return new StringBuilder().append('\'').append(info.getJsonConvert().convertTo(value).replace("\\", "\\\\").replace("'", "\\'")).append('\'').toString();
|
||||
}
|
||||
return String.valueOf(value);
|
||||
}
|
||||
return info.formatToString(value);
|
||||
}
|
||||
|
||||
//----------------------------- insert -----------------------------
|
||||
/**
|
||||
* 新增对象, 必须是Entity对象
|
||||
@@ -784,7 +799,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
||||
return updateDB(info, null, sql, true, colval);
|
||||
} else {
|
||||
String sql = "UPDATE " + info.getTable(pk) + " SET " + info.getSQLColumn(null, column) + " = "
|
||||
+ info.formatToString(info.getSQLValue(column, colval)) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(info.getSQLValue(info.getPrimarySQLColumn(), pk));
|
||||
+ formatValueToString(info, info.getSQLValue(column, colval)) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(info.getSQLValue(info.getPrimarySQLColumn(), pk));
|
||||
return updateDB(info, null, sql, false);
|
||||
}
|
||||
}
|
||||
@@ -856,7 +871,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
||||
return updateDB(info, null, sql, true, colval);
|
||||
} else {
|
||||
String sql = "UPDATE " + info.getTable(node) + " a " + (join1 == null ? "" : (", " + join1))
|
||||
+ " SET " + info.getSQLColumn(alias, column) + " = " + info.formatToString(colval)
|
||||
+ " SET " + info.getSQLColumn(alias, column) + " = " + formatValueToString(info, colval)
|
||||
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
|
||||
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2))));
|
||||
return updateDB(info, null, sql, false);
|
||||
@@ -1142,7 +1157,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
||||
blobs.add((byte[]) val);
|
||||
setsql.append(" = ").append(prepareParamSign(++index));
|
||||
} else {
|
||||
setsql.append(" = ").append(info.formatToString(val));
|
||||
setsql.append(" = ").append(formatValueToString(info, val));
|
||||
}
|
||||
}
|
||||
if (neednode) {
|
||||
@@ -2321,6 +2336,6 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
||||
return CompletableFuture.completedFuture(cache.querySheet(needtotal, selects, flipper, node));
|
||||
}
|
||||
}
|
||||
return querySheetDB(info, needtotal, selects, flipper, node);
|
||||
return querySheetDB(info, readcache, needtotal, selects, flipper, node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,6 +473,15 @@ public final class EntityInfo<T> {
|
||||
this.tablecopySQL = conf.getProperty(DataSources.JDBC_TABLECOPY_SQLTEMPLATE, "CREATE TABLE ${newtable} LIKE ${oldtable}");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取JsonConvert
|
||||
*
|
||||
* @return JsonConvert
|
||||
*/
|
||||
public JsonConvert getJsonConvert() {
|
||||
return jsonConvert;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建主键值,目前只支持UUID赋值
|
||||
*
|
||||
|
||||
@@ -566,6 +566,10 @@ public final class ResourceFactory {
|
||||
list.add(src);
|
||||
Class clazz = src.getClass();
|
||||
do {
|
||||
if (java.lang.Enum.class.isAssignableFrom(clazz)) break;
|
||||
final String cname = clazz.getName();
|
||||
if (cname.startsWith("java.") || cname.startsWith("javax.")
|
||||
|| cname.startsWith("jdk.") || cname.startsWith("sun.")) break;
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers())) continue;
|
||||
field.setAccessible(true);
|
||||
@@ -583,11 +587,10 @@ public final class ResourceFactory {
|
||||
}
|
||||
}
|
||||
if (ns == null) continue;
|
||||
final String nsname = ns.getClass().getName();
|
||||
if (ns.getClass().isPrimitive() || ns.getClass().isArray()
|
||||
|| ns.getClass().getName().startsWith("java.")
|
||||
|| ns.getClass().getName().startsWith("javax.")
|
||||
|| ns.getClass().getName().startsWith("jdk.")
|
||||
|| ns.getClass().getName().startsWith("sun.")) continue;
|
||||
|| nsname.startsWith("java.") || nsname.startsWith("javax.")
|
||||
|| nsname.startsWith("jdk.") || nsname.startsWith("sun.")) continue;
|
||||
if (flag) this.inject(ns, attachment, consumer, list);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1474,9 +1474,11 @@ public final class Utility {
|
||||
final int limit = start + len;
|
||||
for (int i = start; i < limit; i++) {
|
||||
b = bytes[i];
|
||||
if ((b >> 5) == -2) {
|
||||
if ((b >> 5) == -2) {// 2 bytes, 11 bits: 110xxxxx 10xxxxxx
|
||||
size--;
|
||||
} else if ((b >> 4) == -2) {
|
||||
} else if ((b >> 4) == -2) {// 3 bytes, 16 bits: 1110xxxx 10xxxxxx 10xxxxxx
|
||||
size -= 2;
|
||||
} else if ((b >> 3) == -2) {// 4 bytes, 21 bits: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
size -= 2;
|
||||
}
|
||||
}
|
||||
@@ -1484,12 +1486,17 @@ public final class Utility {
|
||||
size = 0;
|
||||
for (int i = start; i < limit;) {
|
||||
b = bytes[i++];
|
||||
if (b >= 0) {
|
||||
if (b >= 0) {// 1 byte, 7 bits: 0xxxxxxx
|
||||
text[size++] = (char) b;
|
||||
} else if ((b >> 5) == -2) {
|
||||
} else if ((b >> 5) == -2) {// 2 bytes, 11 bits: 110xxxxx 10xxxxxx
|
||||
text[size++] = (char) (((b << 6) ^ bytes[i++]) ^ (((byte) 0xC0 << 6) ^ ((byte) 0x80)));
|
||||
} else if ((b >> 4) == -2) {
|
||||
} else if ((b >> 4) == -2) {// 3 bytes, 16 bits: 1110xxxx 10xxxxxx 10xxxxxx
|
||||
text[size++] = (char) ((b << 12) ^ (bytes[i++] << 6) ^ (bytes[i++] ^ (((byte) 0xE0 << 12) ^ ((byte) 0x80 << 6) ^ ((byte) 0x80))));
|
||||
} else if ((b >> 3) == -2) {// 4 bytes, 21 bits: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
int uc = ((b << 18) ^ (bytes[i++] << 12) ^ (bytes[i++] << 6) ^ (bytes[i++] ^ (((byte) 0xF0 << 18) ^ ((byte) 0x80 << 12) ^ ((byte) 0x80 << 6) ^ ((byte) 0x80))));
|
||||
text[size++] = Character.highSurrogate(uc);
|
||||
text[size++] = Character.lowSurrogate(uc);
|
||||
//测试代码 byte[] bs = {(byte)34, (byte)76, (byte)105, (byte)108, (byte)121, (byte)240, (byte)159, (byte)146, (byte)171, (byte)34};
|
||||
}
|
||||
}
|
||||
return text;
|
||||
@@ -1516,6 +1523,8 @@ public final class Utility {
|
||||
size++;
|
||||
} else if (c < 0x800) {
|
||||
size += 2;
|
||||
} else if (Character.isSurrogate(c)) {
|
||||
size += 2;
|
||||
} else {
|
||||
size += 3;
|
||||
}
|
||||
@@ -1529,6 +1538,13 @@ public final class Utility {
|
||||
} else if (c < 0x800) {
|
||||
bytes[size++] = (byte) (0xc0 | (c >> 6));
|
||||
bytes[size++] = (byte) (0x80 | (c & 0x3f));
|
||||
} else if (Character.isSurrogate(c)) { //连取两个
|
||||
int uc = Character.toCodePoint(c, chars[i + 1]);
|
||||
bytes[size++] = (byte) (0xf0 | ((uc >> 18)));
|
||||
bytes[size++] = (byte) (0x80 | ((uc >> 12) & 0x3f));
|
||||
bytes[size++] = (byte) (0x80 | ((uc >> 6) & 0x3f));
|
||||
bytes[size++] = (byte) (0x80 | (uc & 0x3f));
|
||||
i++;
|
||||
} else {
|
||||
bytes[size++] = (byte) (0xe0 | ((c >> 12)));
|
||||
bytes[size++] = (byte) (0x80 | ((c >> 6) & 0x3f));
|
||||
|
||||
Reference in New Issue
Block a user