strip string java_Java StringUtils.strip方法代码示例

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类

public static void copyResourceFolder(String resourceFolder, String destDir)

throws IOException {

final File jarFile = new File(Util.class.getProtectionDomain()

.getCodeSource().getLocation().getPath());

if (jarFile.isFile()) { // Run with JAR file

resourceFolder = StringUtils.strip(resourceFolder, "/");

final JarFile jar = new JarFile(jarFile);

// gives ALL entries in jar

final Enumeration entries = jar.entries();

while (entries.hasMoreElements()) {

JarEntry element = entries.nextElement();

final String name = element.getName();

// filter according to the path

if (name.startsWith(resourceFolder + "/")) {

String resDestDir = Util.combineFilePath(destDir,

name.replaceFirst(resourceFolder + "/", ""));

if (element.isDirectory()) {

File newDir = new File(resDestDir);

if (!newDir.exists()) {

boolean mkdirRes = newDir.mkdirs();

if (!mkdirRes) {

logger.error("Failed to create directory "

+ resDestDir);

}

}

} else {

InputStream inputStream = null;

try {

inputStream = Util.class.getResourceAsStream("/"

+ name);

if (inputStream == null) {

logger.error("No resource is found:" + name);

} else {

Util.outputFile(inputStream, resDestDir);

}

/* compress js files */

inputStream = Util.class.getResourceAsStream("/"

+ name);

compressor.compress(inputStream, name, destDir);

} finally {

if (inputStream != null) {

inputStream.close();

}

}

}

}

}

jar.close();

} else { // Run with IDE

final URL url = Util.class.getResource(resourceFolder);

if (url != null) {

try {

final File src = new File(url.toURI());

File dest = new File(destDir);

FileUtils.copyDirectory(src, dest);

Util.compressFilesInDir(src, destDir);

} catch (URISyntaxException ex) {

logger.error(ex);

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值