enjoy 4.4 release ^_^

This commit is contained in:
James
2019-08-20 21:29:19 +08:00
parent 6156051e16
commit 442a920366
14 changed files with 280 additions and 107 deletions

View File

@@ -50,15 +50,17 @@ public class ByteWriter extends Writer {
}
public void write(String str, int offset, int len) throws IOException {
while (len > chars.length) {
write(str, offset, chars.length);
offset += chars.length;
len -= chars.length;
int size, byteLen;
while (len > 0) {
size = (len > chars.length ? chars.length : len);
str.getChars(offset, offset + size, chars, 0);
byteLen = encoder.encode(chars, 0, size, bytes);
out.write(bytes, 0, byteLen);
offset += size;
len -= size;
}
str.getChars(offset, offset + len, chars, 0);
int byteLen = encoder.encode(chars, 0, len, bytes);
out.write(bytes, 0, byteLen);
}
public void write(String str) throws IOException {
@@ -66,15 +68,17 @@ public class ByteWriter extends Writer {
}
public void write(StringBuilder stringBuilder, int offset, int len) throws IOException {
while (len > chars.length) {
write(stringBuilder, offset, chars.length);
offset += chars.length;
len -= chars.length;
int size, byteLen;
while (len > 0) {
size = (len > chars.length ? chars.length : len);
stringBuilder.getChars(offset, offset + size, chars, 0);
byteLen = encoder.encode(chars, 0, size, bytes);
out.write(bytes, 0, byteLen);
offset += size;
len -= size;
}
stringBuilder.getChars(offset, offset + len, chars, 0);
int byteLen = encoder.encode(chars, 0, len, bytes);
out.write(bytes, 0, byteLen);
}
public void write(StringBuilder stringBuilder) throws IOException {

View File

@@ -44,14 +44,16 @@ public class CharWriter extends Writer {
}
public void write(String str, int offset, int len) throws IOException {
while (len > chars.length) {
write(str, offset, chars.length);
offset += chars.length;
len -= chars.length;
int size;
while (len > 0) {
size = (len > chars.length ? chars.length : len);
str.getChars(offset, offset + size, chars, 0);
out.write(chars, 0, size);
offset += size;
len -= size;
}
str.getChars(offset, offset + len, chars, 0);
out.write(chars, 0, len);
}
public void write(String str) throws IOException {
@@ -59,14 +61,16 @@ public class CharWriter extends Writer {
}
public void write(StringBuilder stringBuilder, int offset, int len) throws IOException {
while (len > chars.length) {
write(stringBuilder, offset, chars.length);
offset += chars.length;
len -= chars.length;
int size;
while (len > 0) {
size = (len > chars.length ? chars.length : len);
stringBuilder.getChars(offset, offset + size, chars, 0);
out.write(chars, 0, size);
offset += size;
len -= size;
}
stringBuilder.getChars(offset, offset + len, chars, 0);
out.write(chars, 0, len);
}
public void write(StringBuilder stringBuilder) throws IOException {

View File

@@ -25,7 +25,7 @@ import java.util.Map;
*/
public class DateFormats {
private Map<String, SimpleDateFormat> map = new HashMap<String, SimpleDateFormat>();
private Map<String, SimpleDateFormat> map = new HashMap<String, SimpleDateFormat>(16, 0.25F);
public SimpleDateFormat getDateFormat(String datePattern) {
SimpleDateFormat ret = map.get(datePattern);

View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jfinal.template.io;
/**
* JdkEncoderFactory
*
* 支持 utf8mb4支持 emoji 表情字符,支持各种罕见字符编码
*
* <pre>
* 配置方法:
* engine.setToJdkEncoderFactory();
* </pre>
*/
public class JdkEncoderFactory extends EncoderFactory {
@Override
public Encoder getEncoder() {
return new JdkEncoder(charset);
}
}

View File

@@ -16,7 +16,7 @@
package com.jfinal.template.io;
import java.nio.charset.MalformedInputException;
// import java.nio.charset.MalformedInputException;
/**
* Utf8Encoder
@@ -62,12 +62,16 @@ public class Utf8Encoder extends Encoder {
if (Character.isLowSurrogate(d)) {
uc = Character.toCodePoint(c, d);
} else {
throw new RuntimeException("encode UTF8 error", new MalformedInputException(1));
// throw new RuntimeException("encode UTF8 error", new MalformedInputException(1));
bytes[dp++] = (byte) '?';
continue;
}
}
} else {
if (Character.isLowSurrogate(c)) {
throw new RuntimeException("encode UTF8 error", new MalformedInputException(1));
// throw new RuntimeException("encode UTF8 error", new MalformedInputException(1));
bytes[dp++] = (byte) '?';
continue;
} else {
uc = c;
}