use of cn.hutool.core.io.StreamProgress in project hutool by looly.
the class ReaderWriterCopier method copy.
@Override
public long copy(Reader source, Writer target) {
Assert.notNull(source, "InputStream is null !");
Assert.notNull(target, "OutputStream is null !");
final StreamProgress progress = this.progress;
if (null != progress) {
progress.start();
}
final long size;
try {
size = doCopy(source, target, new char[bufferSize(this.count)], progress);
target.flush();
} catch (IOException e) {
throw new IORuntimeException(e);
}
if (null != progress) {
progress.finish();
}
return size;
}
use of cn.hutool.core.io.StreamProgress 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.StreamProgress in project hutool by looly.
the class DownloadTest method downloadFileFromUrlTest3.
@Test
@Ignore
public void downloadFileFromUrlTest3() {
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"), 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);
} finally {
FileUtil.del(file);
}
}
use of cn.hutool.core.io.StreamProgress in project hutool by looly.
the class ChannelCopier method copy.
@Override
public long copy(ReadableByteChannel source, WritableByteChannel target) {
Assert.notNull(source, "InputStream is null !");
Assert.notNull(target, "OutputStream is null !");
final StreamProgress progress = this.progress;
if (null != progress) {
progress.start();
}
final long size;
try {
size = doCopy(source, target, ByteBuffer.allocate(bufferSize(this.count)), progress);
} catch (IOException e) {
throw new IORuntimeException(e);
}
if (null != progress) {
progress.finish();
}
return size;
}
use of cn.hutool.core.io.StreamProgress in project hutool by looly.
the class StreamCopier method copy.
@Override
public long copy(InputStream source, OutputStream target) {
Assert.notNull(source, "InputStream is null !");
Assert.notNull(target, "OutputStream is null !");
final StreamProgress progress = this.progress;
if (null != progress) {
progress.start();
}
final long size;
try {
size = doCopy(source, target, new byte[bufferSize(this.count)], progress);
target.flush();
} catch (IOException e) {
throw new IORuntimeException(e);
}
if (null != progress) {
progress.finish();
}
return size;
}
Aggregations