本文整理汇总了Java中org.nutz.lang.Streams类的典型用法代码示例。如果您正苦于以下问题:Java Streams类的具体用法?Java Streams怎么用?Java Streams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Streams类属于org.nutz.lang包,在下文中一共展示了Streams类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: JarResourceLocation
import org.nutz.lang.Streams; //导入依赖的package包/类
public JarResourceLocation(String jarPath) throws IOException {
if (jarPath.startsWith("zip:"))
jarPath = jarPath.substring(4);
if (jarPath.startsWith("file:/")) {
jarPath = jarPath.substring("file:/".length());
if (!new File(jarPath).exists() && !jarPath.startsWith("/")) {
jarPath = "/" + jarPath;
}
}
this.jarPath = new File(jarPath).getAbsoluteFile().getCanonicalPath();
ZipInputStream zis = null;
try {
zis = Scans.makeZipInputStream(jarPath);
ZipEntry ens = null;
while (null != (ens = zis.getNextEntry())) {
if (ens.isDirectory())
continue;
names.add(ens.getName());
}
}
catch (Throwable e) {
throw Lang.wrapThrow(e);
} finally {
Streams.safeClose(zis);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:27,代码来源:ResourceLocation.java
示例2: loadSQL
import org.nutz.lang.Streams; //导入依赖的package包/类
/**
* 执行根据字符流来加载sql内容的操作
*
* @param reader
* @throws IOException
*/
protected void loadSQL(Reader reader) throws IOException {
BufferedReader bufferedReader = null;
try {
if(reader instanceof BufferedReader)
bufferedReader = (BufferedReader)reader;
else
bufferedReader = new BufferedReader(reader);
SqlFileBuilder p = new SqlFileBuilder(bufferedReader);
_sql_keys = new ArrayList<String>(p.map.size());
for (Entry<String, String> en : p.entrySet()) {
addSql(en.getKey(), Strings.trim(en.getValue()));
}
}
finally {
Streams.safeClose(bufferedReader);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:25,代码来源:AbstractSqlManager.java
示例3: toJsonFile
import org.nutz.lang.Streams; //导入依赖的package包/类
/**
* 将一个 JAVA 对象以 JSON 的形式写到一个文件里,并且可以设定 JSON 字符串的格式化方式
*
* @param f
* 文本文件
* @param obj
* JAVA 对象
* @param format
* JSON 字符串格式化方式 ,若 format 为 null ,则以 JsonFormat.nice() 格式输出
*/
public static void toJsonFile(File f, Object obj, JsonFormat format) {
Writer writer = null;
try {
Files.createFileIfNoExists(f);
writer = Streams.fileOutw(f);
Json.toJson(writer, obj, format);
writer.append('\n');
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
finally {
Streams.safeClose(writer);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:26,代码来源:Json.java
示例4: send
import org.nutz.lang.Streams; //导入依赖的package包/类
/**
* 向某主机发送一些字节内容,并将返回写入输出流
*
* @param host
* 主机
* @param port
* 端口
* @param ins
* 发送的内容
* @param ops
* 主机返回的输入流
*/
public static void send(String host, int port, InputStream ins, OutputStream ops, int timeout) {
Socket socket = null;
try {
socket = new Socket();
socket.connect(InetSocketAddress.createUnresolved(host, port), timeout);
// 发送关闭命令
OutputStream sOut = socket.getOutputStream();
Streams.write(sOut, ins);
sOut.flush();
// 接收服务器的反馈
if (!socket.isClosed()) {
InputStream sReturn = socket.getInputStream();
Streams.write(ops, sReturn);
}
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
finally {
Streams.safeClose(ins);
Streams.safeClose(ops);
safeClose(socket);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:38,代码来源:Sockets.java
示例5: load
import org.nutz.lang.Streams; //导入依赖的package包/类
protected void load(String... confFilesPath) {
if (log.isDebugEnabled()) {
log.debugf("Loading config files[%s].", confFilesPath);
}
InputStream is = null;
BufferedReader br = null;
Properties p = new Properties();
try {
for (String confFilePath : confFilesPath) {
is = this.getClass().getResourceAsStream(confFilePath);
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
p.load(br);
}
}
catch (Exception e) {
throw Lang.wrapThrow(e);
}
finally {
Streams.safeClose(is);
Streams.safeClose(br);
}
putAll(p);
}
开发者ID:elkan1788,项目名称:mpsdk4j,代码行数:24,代码来源:ConfigReader.java
示例6: _set_cache_item
import org.nutz.lang.Streams; //导入依赖的package包/类
private void _set_cache_item(final ZCache<ZDocTmplObj> zc, String fname) {
if (!Strings.isBlank(fname)) {
topIgnores.add(fname);
final ZDir d = src.getDir(fname);
if (null != d) {
d.walk(true, new ZFWalker() {
public boolean invoke(int i, ZFile f) {
if (f.isDir())
return true;
if (f.isHidden())
return false;
ZDocTmplObj ci = new ZDocTmplObj();
ci.file(f).raw(Streams.readAndClose(io.readString(f)));
String rph = d.relative(f);
String key = ZD.rph2key(rph);
zc.set(key, ci);
return true;
}
});
}
}
}
开发者ID:zozoh,项目名称:zdoc,代码行数:23,代码来源:ZDocHome.java
示例7: _gen_tag_page
import org.nutz.lang.Streams; //导入依赖的package包/类
private void _gen_tag_page(Rendering ing,
ZDocTemplate tmpl,
NutMap page,
ZDocTag tag) {
page.setv("title", tag.getText());
ing.context().setv("tag", tag.genItems());
// 在目标目录创建对应文件
ZFile destf = dest.createFileIfNoExists(tagPath
+ "/"
+ tag.getKey()
+ ".html");
// 准备渲染
Writer wr = Streams.utf8w(ing.io().openOutputStream(destf));
tmpl.outputTo(wr, ing.context());
Streams.safeClose(wr);
}
开发者ID:zozoh,项目名称:zdoc,代码行数:18,代码来源:RenderToHtml.java
示例8: init
import org.nutz.lang.Streams; //导入依赖的package包/类
/**
* 从一个流读取数据库配置
* @param in 输入流,包含配置信息
* @throws IOException 读取失败是抛出异常
*/
public void init(InputStream in) throws IOException {
Properties props = new Properties();
try {
props.load(in);
init(props);
}
finally {
Streams.safeClose(in);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:16,代码来源:DaoUp.java
示例9: getBytes
import org.nutz.lang.Streams; //导入依赖的package包/类
public byte[] getBytes(long pos, int length) throws SQLException {
if (pos == 1 && length == length())
try {
return Streams.readBytes(getBinaryStream());
} catch (IOException e) {
}
throw Lang.noImplement();
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:9,代码来源:SimpleBlob.java
示例10: saveAs
import org.nutz.lang.Streams; //导入依赖的package包/类
public void saveAs(File f) throws IOException {
Writer w = Streams.fileOutw(f);
for (String key : keylist()) {
w.append("/*").append(Strings.dup('-', 60)).append("*/\n");
String sql = map().get(key);
w.append(format("/*%s*/\n", key));
w.append(sql).append('\n');
}
w.flush();
w.close();
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:12,代码来源:AbstractSqlManager.java
示例11: SqlFileBuilder
import org.nutz.lang.Streams; //导入依赖的package包/类
SqlFileBuilder(BufferedReader reader) throws IOException {
InnerStack stack = new InnerStack();
int c;
stack.eat('\n');
while (-1 != (c = reader.read())) {
stack.eat(c);
}
if (stack.key != null)
stack.addOne();
map = stack.map;
Streams.safeClose(reader);
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:13,代码来源:AbstractSqlManager.java
示例12: get
import org.nutz.lang.Streams; //导入依赖的package包/类
public Object get(ResultSet rs, String colName) throws SQLException {
File f = this.createTempFile();
Clob clob = rs.getClob(colName);
if (clob == null)
return null;
Streams.writeAndClose(Streams.fileOutw(f), clob.getCharacterStream());
return new SimpleClob(f);
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:9,代码来源:ClobValueAdaptor.java
示例13: fromJsonFile
import org.nutz.lang.Streams; //导入依赖的package包/类
/**
* 根据指定的类型,读取指定的 JSON 文件生成 JAVA 对象。 指定的类型可以是任意 JAVA 对象。
*
* @param type
* 对象类型
* @param f
* 文件对象
* @return 指定类型的 JAVA 对象
* @throws JsonException
*/
public static <T> T fromJsonFile(Class<T> type, File f) {
BufferedReader br = null;
try {
br = buffr(fileInr(f));
return Json.fromJson(type, br);
}
finally {
Streams.safeClose(br);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:21,代码来源:Json.java
示例14: toString
import org.nutz.lang.Streams; //导入依赖的package包/类
public String toString(String charset) throws IOException {
index = 0;
cursor = 0;
StringBuilder sb = new StringBuilder();
StringOutputStream sos = new StringOutputStream(sb, charset);
byte c;
while ((c = (byte) this.read()) != -1)
sos.write(c);
Streams.safeFlush(sos);
Streams.safeClose(sos);
return sb.toString();
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:13,代码来源:StreamBuffer.java
示例15: buildSnaker
import org.nutz.lang.Streams; //导入依赖的package包/类
protected static SnakerEngine buildSnaker(DataSource ds, Object...paths) throws IOException {
// 首先,我们构建一个snaker的上下文
SimpleContext ctx = new SimpleContext();
// 将集成nutz所必须的两个类,关联之. 这样使用者仅需要声明本IocLoader即可完成全部配置
ctx.put(NutzAccess.class.getName(), NutzAccess.class);
ctx.put(NutzTransactionInterceptor.class.getName(), NutzTransactionInterceptor.class);
// 开始构建sanker的配置对象
Configuration cnf = new Configuration(ctx);
cnf.initAccessDBObject(ds);
SnakerEngine engine = cnf.buildSnakerEngine();
// 如果用户声明了流程描述文件的路径,加载之
if (paths != null) {
for (Object path : paths) {
for(NutResource re : Scans.me().scan(String.valueOf(path))) {
if (log.isDebugEnabled())
log.debug("Found snakerflow xml > " + re.getName());
//*********************************************************
// 这部分属于hack的部分, 因为snaker并不识别相同的流程配置,而是简单地作为新流程
// 所以,需要自行查询一下是不是数据相同,不一样的时候才deploy
byte[] data = Streams.readBytesAndClose(re.getInputStream());
ProcessModel model = ModelParser.parse(data);
List<Process> list = ctx.find(DBAccess.class).queryList(Process.class, querySql, model.getName());
if (!list.isEmpty()) {
Process p = list.get(0);
byte[] cnt = p.getDBContent();
if (cnt != null && Arrays.equals(cnt, data)) {
log.debug("Same snakerflow xml > " + re.getName() + " skiped");
continue;
}
}
//*********************************************************
// 同名的流程数据有更新或这是全新的流程,部署之
engine.process().deploy(new ByteArrayInputStream(data));
}
}
}
// 工厂方法完成, snaker引擎已经准备好了,可以返回了
return engine;
}
开发者ID:snakerflow,项目名称:snakerflow,代码行数:40,代码来源:SnakerIocLoader.java
示例16: upload
import org.nutz.lang.Streams; //导入依赖的package包/类
@At({"/up", "/up/?"})
@AdaptBy(type=VoidAdaptor.class)
public void upload(long sensor_id, @Attr(IotKeys.UID)long userId, HttpServletResponse resp, HttpServletRequest req) throws IOException {
if (req.getHeader("Content-Length") == null) {
badReq(resp, Iots.NEED_CONTENT_LENGTH);
return;
}
if (req.getContentLength() < 1) {
badReq(resp, Iots.EMTRY_BODY);
return;
}
if (req.getContentLength() > 1024*1024) {
badReq(resp, Iots.TOOBIG);
return;
}
if (sensor_id > 0) { // 图片上传
IotSensor sensor = dao.fetch(IotSensor.class, Cnd.where("id", "=", sensor_id).and(IotKeys.UID, "=", userId));
if (sensor == null) {
badReq(resp, Iots.NOTFOUND);
return;
}
// 保存一下
File tmp = File.createTempFile("iot", ".jpg");
try {
Files.write(tmp, req.getInputStream());
BufferedImage image = Images.read(tmp);
iotSensorService.saveImage(sensor, tmp, image.getWidth(), image.getHeight());
} catch (Exception e) {
log.info("bad image", e);
} finally {
tmp.delete();
}
} else {
// 普通上传
iotHttpCmdHandler.exec(resp.getWriter(), Streams.readAndClose(req.getReader()), iotSensorService, dao);
}
}
开发者ID:wendal,项目名称:whale,代码行数:38,代码来源:IotExchangeModule.java
示例17: console
import org.nutz.lang.Streams; //导入依赖的package包/类
@At("/console/?")
@AdaptBy(type=VoidAdaptor.class)
@POST
@Ok("json")
public Object console(String openid, @Attr(value="usr", scope=Scope.SESSION)String usr, InputStream in) throws LuaException {
WxMpInfo master = (WxMpInfo) wxctx.get(openid);
if (master == null || !usr.equals(master.getOwner())) {
return new HttpStatusView(403);
}
WxAPI wxapi = wxctx.getAPI(openid);
LuaState lua = sandbox(openid);
try {
String str = Streams.readAndClose(new InputStreamReader(in));
lua.pushJavaObject(wxapi);
lua.setGlobal("wxapi");
lua.pushJavaObject(Wxs.class);
lua.setGlobal("wxs");
// "wxs = luajava.bindClass('org.nutz.weixin.util.Wxs')\n"+
int re = lua.LloadString(str);
if (re != 0) {
return "lua error re="+re + ", msg=" + lua.getLuaObject(1);
}
lua.pcall(0, 1, 0);
if (re != 0) {
return "lua error re="+re + ", msg=" + lua.getLuaObject(1);
}
return LUAs.toJavaObject(lua.getLuaObject(1));
} finally {
lua.close();
}
}
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:32,代码来源:WxManagerModule.java
示例18: get
import org.nutz.lang.Streams; //导入依赖的package包/类
public WxAccessToken get() {
Map<String, String> map;
Jedis jedis = null;
try {
jedis = jedisAgent.getResource();
map = jedis.hgetAll(tokenKey);
} finally {
Streams.safeClose(jedis);
}
if (map == null || map.isEmpty())
return null;
return Lang.map2Object(map, WxAccessToken.class);
}
开发者ID:nutzam,项目名称:nutzwx,代码行数:14,代码来源:JedisAgenAccessTokenStore.java
示例19: save
import org.nutz.lang.Streams; //导入依赖的package包/类
public void save(String token, int expires, long lastCacheTimeMillis) {
Map<String, String> map = new HashMap<String, String>();
map.put("token", token);
map.put("expires", "" + expires);
map.put("lastCacheTimeMillis", "" + lastCacheTimeMillis);
Jedis jedis = null;
try {
jedis = jedisAgent.getResource();
jedis.hmset(tokenKey, map);
} finally {
Streams.safeClose(jedis);
}
}
开发者ID:nutzam,项目名称:nutzwx,代码行数:14,代码来源:JedisAgenAccessTokenStore.java
示例20: convert
import org.nutz.lang.Streams; //导入依赖的package包/类
/**
* 将一个输入流转为WxInMsg
*/
public static <T> T convert(InputStream in, Class<T> klass) {
Map<String, Object> map;
String raw;
try {
// fix:
// DocumentBuilder不支持直接传入Reader,如果直接传InputStream的话又按系统默认编码,所以,用InputSource中转一下
Reader r = Streams.utf8r(in);
raw = Lang.readAll(r);
map = Xmls.asMap(Xmls.xmls()
.parse(new InputSource(new StringReader(raw)))
.getDocumentElement());
}
catch (Exception e) {
throw Lang.wrapThrow(e);
}
Lang.convertMapKey(map, new MapKeyConvertor() {
@Override
public String convertKey(String key) {
return Strings.lowerFirst(key);
}
}, true);
if (DEV_MODE) {
log.debug("Income >> \n" + Json.toJson(map));
}
T t = Lang.map2Object(map, klass);
if (t instanceof WxInMsg)
((WxInMsg) t).raw(raw);
else if (t instanceof WxOutMsg)
((WxOutMsg) t).raw(raw);
return t;
}
开发者ID:nutzam,项目名称:nutzwx,代码行数:36,代码来源:Wxs.java
注:本文中的org.nutz.lang.Streams类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论