use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class Ftp method delFile.
@Override
public boolean delFile(String path) throws IORuntimeException {
final String pwd = pwd();
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
if (false == isDir(dir)) {
throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path);
}
boolean isSuccess;
try {
isSuccess = client.deleteFile(fileName);
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
// 回到原目录
cd(pwd);
}
return isSuccess;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class Mail method addImage.
/**
* 增加图片,图片的键对应到邮件模板中的占位字符串
*
* @param cid 图片与占位符,占位符格式为cid:${cid}
* @param imageStream 图片流,不关闭
* @param contentType 图片类型,null赋值默认的"image/jpeg"
* @return this
* @since 4.6.3
*/
public Mail addImage(String cid, InputStream imageStream, String contentType) {
ByteArrayDataSource imgSource;
try {
imgSource = new ByteArrayDataSource(imageStream, ObjectUtil.defaultIfNull(contentType, "image/jpeg"));
} catch (IOException e) {
throw new IORuntimeException(e);
}
imgSource.setName(cid);
return setAttachments(imgSource);
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class DownloadTest method downloadFileFromUrlTest2.
@Test
@Ignore
public void downloadFileFromUrlTest2() {
File file = null;
try {
file = HttpUtil.downloadFileFromUrl("https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.4.0/hutool-all-5.4.0-sources.jar", FileUtil.file("d:/download/temp"), 1, new StreamProgress() {
@Override
public void start() {
System.out.println("start");
}
@Override
public void progress(long progressSize) {
System.out.println("download size:" + progressSize);
}
@Override
public void finish() {
System.out.println("end");
}
});
Assert.assertNotNull(file);
Assert.assertTrue(file.exists());
Assert.assertTrue(file.isFile());
Assert.assertTrue(file.length() > 0);
Assert.assertTrue(file.getName().length() > 0);
} catch (Exception e) {
Assert.assertTrue(e instanceof IORuntimeException);
} finally {
FileUtil.del(file);
}
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class ExcelFileUtil method getFileMagic.
/**
* {@link java.io.PushbackInputStream}
* PushbackInputStream的markSupported()为false,并不支持mark和reset
* 如果强转成PushbackInputStream在调用FileMagic.valueOf(inputStream)时会报错
* {@link FileMagic}
* 报错内容:getFileMagic() only operates on streams which support mark(int)
* 此处修改成 final InputStream in = FileMagic.prepareToCheckMagic(in)
*
* @param in {@link InputStream}
* @author kefan.qu
*/
private static FileMagic getFileMagic(InputStream in) {
FileMagic magic;
in = FileMagic.prepareToCheckMagic(in);
try {
magic = FileMagic.valueOf(in);
} catch (IOException e) {
throw new IORuntimeException(e);
}
return magic;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class Gzip method unGzip.
/**
* 将压缩流解压到target中
*
* @return Gzip
*/
public Gzip unGzip() {
try {
source = (source instanceof GZIPInputStream) ? (GZIPInputStream) source : new GZIPInputStream(source);
IoUtil.copy(source, target);
} catch (IOException e) {
throw new IORuntimeException(e);
}
return this;
}
Aggregations