本文整理汇总了Java中org.nutz.lang.Files类的典型用法代码示例。如果您正苦于以下问题:Java Files类的具体用法?Java Files怎么用?Java Files使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Files类属于org.nutz.lang包,在下文中一共展示了Files类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: del
import org.nutz.lang.Files; //导入依赖的package包/类
@At
@Ok("json")
public Map<String,String> del(@Param("id")Long id,HttpServletRequest request)
{
Img img = imgService.fetch(id);
if (img.getImgurl() != null && img.getImgurl().trim().length() > 2)
{
String webPath = request.getSession().getServletContext().getRealPath("/");
String appPath = webPath.substring(0,webPath.length() - 1) + "upload/";
Files.deleteFile(new File(appPath + img.getImgurl().trim()));
}
int num = imgService.delete(id);
CacheManager.getInstance().getCache(ImgService.CACHE_NAME).removeAll();
return Bjui.rtnMap((num > 0) ? true : false , "tab_img",false);
}
开发者ID:lq10001,项目名称:product,代码行数:20,代码来源:ImgAction.java
示例2: image
import org.nutz.lang.Files; //导入依赖的package包/类
/**
* 发送图片,上传图片接口
* @param file
* @param context
* @return
*/
@At
@POST
@Filters({@By(type=CrossOriginFilter.class)})
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" })
public Object image(@Param("file") TempFile file,ServletContext context){
System.out.println(file.getName());
System.out.println(file.getMeta().getFileLocalName());
String relpath = getDir()+"/upload/imgs/"+file.getMeta().getFileLocalName(); // 此为: D:\\apache-tomcat-8.0.36\\webapps\\upload\\tomat.png
Files.copy(file.getFile(),new File(relpath));
String url ="/upload/imgs/"+file.getMeta().getFileLocalName(); //eclipse默认的tomcat目录是在其缓存文件中,你要自己指定到tomcat所在目录
//构建json数据
Map<String,Object> data = new HashMap<String,Object>();
data.put("code", "0");
data.put("msg", "");
Map<String,String> sourceUrl = new HashMap<String,String>();
sourceUrl.put("src", url);
data.put("data", sourceUrl);
return data;
}
开发者ID:TopCoderMyDream,项目名称:LuliChat,代码行数:28,代码来源:UploadModule.java
示例3: files
import org.nutz.lang.Files; //导入依赖的package包/类
/**
* 发送图片,上传图片接口
* @param file
* @param context
* @return
*/
@At
@POST
@Filters({@By(type=CrossOriginFilter.class)})
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" })
public Object files(@Param("file") TempFile file,ServletContext context){
System.out.println(file.getName());
System.out.println(file.getMeta().getFileLocalName());
String relpath = getDir()+"/upload/files/"+file.getMeta().getFileLocalName(); // 此为: D:\\apache-tomcat-8.0.36\\webapps\\upload\\tomat.png
Files.copy(file.getFile(),new File(relpath));
String url ="/upload/files/"+file.getMeta().getFileLocalName(); //eclipse默认的tomcat目录是在其缓存文件中,你要自己指定到tomcat所在目录
//构建json数据
Map<String,Object> data = new HashMap<String,Object>();
data.put("code", "0");
data.put("msg", "");
Map<String,String> sourceUrl = new HashMap<String,String>();
sourceUrl.put("src", url);
data.put("data", sourceUrl);
return data;
}
开发者ID:TopCoderMyDream,项目名称:LuliChat,代码行数:27,代码来源:UploadModule.java
示例4: toJsonFile
import org.nutz.lang.Files; //导入依赖的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
示例5: createFile
import org.nutz.lang.Files; //导入依赖的package包/类
public File createFile(String suffix) {
if (size > 0 && cursor >= size)
cursor = -1;
long id = ++cursor;
if (size > 0 && id >= size)
Lang.makeThrow("Id (%d) is out of range (%d)", id, size);
File re = Pools.getFileById(home, id, suffix);
if (!re.exists())
try {
Files.createNewFile(re);
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
return re;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:17,代码来源:NutFilePool.java
示例6: doFile
import org.nutz.lang.Files; //导入依赖的package包/类
static void doFile(File f) {
// 处理文件名
String fnm = f.getName()
.replaceAll("_projectName_", np.getProjectName())
.replaceAll("_mainName_", np.getMainName());
String rph = Files.renamePath(Disks.getRelativePath(tmplHome, f), fnm);
log.infof(" + %s", rph);
// 创建目标文件
File fDest = Files.getFile(projectHome, rph);
Files.createFileIfNoExists(fDest);
// 处理文件的内容
Segment seg = Segments.read(f);
String str = seg.render(ctx).toString();
Files.write(fDest, str);
}
开发者ID:zozoh,项目名称:nutz-origin,代码行数:19,代码来源:ZOrigin.java
示例7: render
import org.nutz.lang.Files; //导入依赖的package包/类
public void render(HttpServletRequest req, HttpServletResponse resp,
Object obj) throws Exception {
String path = evalPath(req, obj);
String args = "";
if (path != null && path.contains("?")) { // 将参数部分分解出来
args = path.substring(path.indexOf('?'));
path = path.substring(0, path.indexOf('?'));
}
String ext = getExt();
// 空路径,采用默认规则
if (Strings.isBlank(path)) {
path = Mvcs.getRequestPath(req);
path = (path.startsWith("/") ? "" : "/")
+ Files.renameSuffix(path, ext);
}
// 绝对路径 : 以 '/' 开头的路径不增加 '/WEB-INF'
else if (path.charAt(0) == '/') {
if (!path.toLowerCase().endsWith(ext))
path += ext;
}
// 包名形式的路径
else {
path = path.replace('.', '/') + ext;
}
// 执行 Forward
path = path + args;
RequestDispatcher rd = req.getRequestDispatcher(path);
if (rd == null)
throw Lang.makeThrow("Fail to find Forward '%s'", path);
// Do rendering
rd.forward(req, resp);
}
开发者ID:TopCoderMyDream,项目名称:LuliChat,代码行数:35,代码来源:FreeMakerView.java
示例8: get
import org.nutz.lang.Files; //导入依赖的package包/类
public Object get(ResultSet rs, String colName) throws SQLException {
InputStream in = rs.getBinaryStream(colName);
if (in == null) {
return in;
}
try {
File f = File.createTempFile("nutzdao_blob", ".tmp");
Files.write(f, in);
in.close();
return new ReadOnceInputStream(f);
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:16,代码来源:Jdbcs.java
示例9: getSubString
import org.nutz.lang.Files; //导入依赖的package包/类
public String getSubString(long pos, int length) throws SQLException {
if (pos < 1)
throw new SQLException("pos<1");
pos--;
String str = Files.read(file);
if (pos >= length)
throw new IllegalArgumentException("pos="+pos);
if (pos + length >= length())
return str.substring((int)pos);
return str.substring((int)pos, (int)(pos + length - 1));
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:12,代码来源:SimpleClob.java
示例10: get
import org.nutz.lang.Files; //导入依赖的package包/类
public Object get(ResultSet rs, String colName) throws SQLException {
File f = this.createTempFile();
Blob blob = rs.getBlob(colName);
if (blob == null)
return null;
Files.write(f, blob.getBinaryStream());
return new SimpleBlob(f);
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:9,代码来源:BlobValueAdaptor.java
示例11: write
import org.nutz.lang.Files; //导入依赖的package包/类
/**
* 将内存中一个图片写入目标文件
*
* @param im
* 图片对象
* @param targetFile
* 目标文件,根据其后缀,来决定写入何种图片格式
*/
public static void write(RenderedImage im, File targetFile) {
try {
ImageIO.write(im, Files.getSuffixName(targetFile), targetFile);
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:17,代码来源:Images.java
示例12: SimpleFilePool
import org.nutz.lang.Files; //导入依赖的package包/类
public SimpleFilePool(String homePath, long max) {
if (log.isInfoEnabled()) {
log.infof("Init simple-file-pool by: %s [%s]", homePath, max);
}
this.max = max;
this.home = Files.createDirIfNoExists(homePath);
this.current = 0;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:9,代码来源:SimpleFilePool.java
示例13: createFile
import org.nutz.lang.Files; //导入依赖的package包/类
public synchronized File createFile(String suffix) {
File f = _F(current++, suffix);
if (current > max)
current = 0;
if (!f.exists())
try {
Files.createNewFile(f);
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
return f;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:14,代码来源:SimpleFilePool.java
示例14: getFileId
import org.nutz.lang.Files; //导入依赖的package包/类
public long getFileId(File f) {
String nm = Files.getMajorName(f);
try {
return Long.parseLong(nm);
}
catch (NumberFormatException e) {}
return -1;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:9,代码来源:SimpleFilePool.java
示例15: returnFile
import org.nutz.lang.Files; //导入依赖的package包/类
public synchronized File returnFile(long fId, String suffix) {
File re = _F(fId, suffix);
if (!re.exists())
try {
Files.createNewFile(re);
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
return re;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:12,代码来源:SimpleFilePool.java
示例16: createDir
import org.nutz.lang.Files; //导入依赖的package包/类
public synchronized File createDir() {
File f = _F(current++, null);
if (current > max)
current = 0;
if (f.exists())
Files.clearDir(f);
else
Files.makeDir(f);
return f;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:11,代码来源:SimpleFilePool.java
示例17: returnFile
import org.nutz.lang.Files; //导入依赖的package包/类
public File returnFile(long fId, String suffix) {
File f = Pools.getFileById(home, fId, suffix);
if (!f.exists())
try {
Files.createNewFile(f);
}
catch (IOException e) {
throw Lang.wrapThrow(e);
}
return f;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:12,代码来源:NutFilePool.java
示例18: createDir
import org.nutz.lang.Files; //导入依赖的package包/类
public File createDir() {
if (size > 0 && cursor >= size)
cursor = -1;
long id = ++cursor;
if (size > 0 && id >= size)
Lang.makeThrow("Id (%d) is out of range (%d)", id, size);
return Files.createDirIfNoExists(Pools.getFilePathById(home, id, null));
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:10,代码来源:NutFilePool.java
示例19: removeDir
import org.nutz.lang.Files; //导入依赖的package包/类
public File removeDir(long fId) {
File f = Pools.getFileById(home, fId, null);
if (f.isDirectory()) {
Files.deleteDir(f);
} else {
Files.deleteFile(f);
}
return f;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:10,代码来源:NutFilePool.java
示例20: loadResource
import org.nutz.lang.Files; //导入依赖的package包/类
/**
* 加载资源
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private void loadResource(String... paths) {
for (String path : paths) {
List<NutResource> resources;
if (path.endsWith(".js") || path.endsWith(".json")) {
File f = Files.findFile(path);
resources = new ArrayList<NutResource>();
resources.add(new FileResource(f));
} else {
resources = Scans.me().scan(path, "\\.(js|json)$");
}
for (NutResource nr : resources) {
try {
Object obj = Json.fromJson(nr.getReader());
if (obj instanceof Map) {
Map m = (Map) obj;
map = (Map) Mapl.merge(map, m);
for (Object key : m.keySet()) {
if (key.equals("include")) {
map.remove("include");
List<String> include = (List) m.get("include");
loadResource(include.toArray(new String[include.size()]));
}
}
}
}
catch (Throwable e) {
if (log.isWarnEnabled())
log.warn("Fail to load config?! for " + nr.getName(), e);
}
}
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:38,代码来源:NutConf.java
注:本文中的org.nutz.lang.Files类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论