mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add YamlUtil
This commit is contained in:
@@ -147,8 +147,8 @@ public class AnimatedGifEncoder {
|
||||
/**
|
||||
* Adds next GIF frame. The frame is not written immediately, but is
|
||||
* actually deferred until the next frame is received so that timing
|
||||
* data can be inserted. Invoking <code>finish()</code> flushes all
|
||||
* frames. If <code>setSize</code> was not invoked, the size of the
|
||||
* data can be inserted. Invoking {@code finish()} flushes all
|
||||
* frames. If {@code setSize} was not invoked, the size of the
|
||||
* first image is used for all subsequent frames.
|
||||
*
|
||||
* @param im BufferedImage containing frame to write.
|
||||
@@ -225,7 +225,7 @@ public class AnimatedGifEncoder {
|
||||
|
||||
/**
|
||||
* Sets frame rate in frames per second. Equivalent to
|
||||
* <code>setDelay(1000/fps)</code>.
|
||||
* {@code setDelay(1000/fps)}.
|
||||
*
|
||||
* @param fps float frame rate (frames per second)
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.io.PushbackInputStream;
|
||||
* </code>
|
||||
* <br><br>
|
||||
* 参考: http://akini.mbnet.fi/java/unicodereader/UnicodeInputStream.java.txt
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class BOMInputStream extends InputStream {
|
||||
|
||||
@@ -36,10 +38,21 @@ public class BOMInputStream extends InputStream {
|
||||
private static final int BOM_SIZE = 4;
|
||||
|
||||
// ----------------------------------------------------------------- Constructor start
|
||||
|
||||
/**
|
||||
* 构造
|
||||
* @param in 流
|
||||
*/
|
||||
public BOMInputStream(InputStream in) {
|
||||
this(in, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param in 流
|
||||
* @param defaultCharset 默认编码
|
||||
*/
|
||||
public BOMInputStream(InputStream in, String defaultCharset) {
|
||||
this.in = new PushbackInputStream(in, BOM_SIZE);
|
||||
this.defaultCharset = defaultCharset;
|
||||
@@ -61,7 +74,7 @@ public class BOMInputStream extends InputStream {
|
||||
* @return 编码
|
||||
*/
|
||||
public String getCharset() {
|
||||
if (!isInited) {
|
||||
if (false == isInited) {
|
||||
try {
|
||||
init();
|
||||
} catch (IOException ex) {
|
||||
@@ -117,7 +130,6 @@ public class BOMInputStream extends InputStream {
|
||||
charset = defaultCharset;
|
||||
unread = n;
|
||||
}
|
||||
// System.out.println("read=" + n + ", unread=" + unread);
|
||||
|
||||
if (unread > 0) {
|
||||
in.unread(bom, (n - unread), unread);
|
||||
|
||||
58
hutool-core/src/main/java/cn/hutool/core/io/BomReader.java
Normal file
58
hutool-core/src/main/java/cn/hutool/core/io/BomReader.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 读取带BOM头的流内容的Reader,如果非bom的流或无法识别的编码,则默认UTF-8<br>
|
||||
* BOM定义:http://www.unicode.org/unicode/faq/utf_bom.html
|
||||
*
|
||||
* <ul>
|
||||
* <li>00 00 FE FF = UTF-32, big-endian</li>
|
||||
* <li>FF FE 00 00 = UTF-32, little-endian</li>
|
||||
* <li>EF BB BF = UTF-8</li>
|
||||
* <li>FE FF = UTF-16, big-endian</li>
|
||||
* <li>FF FE = UTF-16, little-endian</li>
|
||||
* </ul>
|
||||
* 使用: <br>
|
||||
* <code>
|
||||
* FileInputStream fis = new FileInputStream(file); <br>
|
||||
* BomReader uin = new BomReader(fis); <br>
|
||||
* </code>
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.7.14
|
||||
*/
|
||||
public class BomReader extends Reader {
|
||||
|
||||
private InputStreamReader reader;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param in 流
|
||||
*/
|
||||
public BomReader(InputStream in) {
|
||||
Assert.notNull(in, "InputStream must be not null!");
|
||||
final BOMInputStream bin = (in instanceof BOMInputStream) ? (BOMInputStream) in : new BOMInputStream(in);
|
||||
try {
|
||||
this.reader = new InputStreamReader(bin, bin.getCharset());
|
||||
} catch (UnsupportedEncodingException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(char[] cbuf, int off, int len) throws IOException {
|
||||
return reader.read(cbuf, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
@@ -224,6 +224,17 @@ public class IoUtil extends NioUtil {
|
||||
return getReader(in, in.getCharset());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从{@link InputStream}中获取{@link BomReader}
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
* @return {@link BomReader}
|
||||
* @since 5.7.14
|
||||
*/
|
||||
public static BomReader getBomReader(InputStream in) {
|
||||
return new BomReader(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得一个Reader
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.lang;
|
||||
|
||||
import cn.hutool.core.bean.BeanPath;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
@@ -76,7 +77,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
|
||||
* <p>奇数参数必须为value,可以为任意类型。</p>
|
||||
*
|
||||
* <pre>
|
||||
Dict dict = Dict.of(
|
||||
* Dict dict = Dict.of(
|
||||
* "RED", "#FF0000",
|
||||
* "GREEN", "#00FF00",
|
||||
* "BLUE", "#0000FF"
|
||||
@@ -91,10 +92,10 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
|
||||
final Dict dict = create();
|
||||
|
||||
String key = null;
|
||||
for(int i = 0; i < keysAndValues.length; i++){
|
||||
if(i % 2 == 0){
|
||||
for (int i = 0; i < keysAndValues.length; i++) {
|
||||
if (i % 2 == 0) {
|
||||
key = Convert.toStr(keysAndValues[i]);
|
||||
} else{
|
||||
} else {
|
||||
dict.put(key, keysAndValues[i]);
|
||||
}
|
||||
}
|
||||
@@ -504,6 +505,61 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
|
||||
public Number getNumber(String attr) {
|
||||
return get(attr, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过表达式获取JSON中嵌套的对象<br>
|
||||
* <ol>
|
||||
* <li>.表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值</li>
|
||||
* <li>[]表达式,可以获取集合等对象中对应index的值</li>
|
||||
* </ol>
|
||||
* <p>
|
||||
* 表达式栗子:
|
||||
*
|
||||
* <pre>
|
||||
* persion
|
||||
* persion.name
|
||||
* persons[3]
|
||||
* person.friends[5].name
|
||||
* </pre>
|
||||
*
|
||||
* @param expression 表达式
|
||||
* @return 对象
|
||||
* @see BeanPath#get(Object)
|
||||
* @since 5.7.14
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getByPath(String expression) {
|
||||
return (T) BeanPath.create(expression).get(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过表达式获取JSON中嵌套的对象<br>
|
||||
* <ol>
|
||||
* <li>.表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值</li>
|
||||
* <li>[]表达式,可以获取集合等对象中对应index的值</li>
|
||||
* </ol>
|
||||
* <p>
|
||||
* 表达式栗子:
|
||||
*
|
||||
* <pre>
|
||||
* persion
|
||||
* persion.name
|
||||
* persons[3]
|
||||
* person.friends[5].name
|
||||
* </pre>
|
||||
* <p>
|
||||
* 获取表达式对应值后转换为对应类型的值
|
||||
*
|
||||
* @param <T> 返回值类型
|
||||
* @param expression 表达式
|
||||
* @param resultType 返回值类型
|
||||
* @return 对象
|
||||
* @see BeanPath#get(Object)
|
||||
* @since 5.7.14
|
||||
*/
|
||||
public <T> T getByPath(String expression, Class<T> resultType) {
|
||||
return Convert.convert(resultType, getByPath(expression));
|
||||
}
|
||||
// -------------------------------------------------------------------- Get end
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user