Skip to content

Commit

Permalink
download2
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghanzheng committed Nov 3, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
jdarwood007 Jeremy D
1 parent 9f5e468 commit 1bfa48e
Showing 27 changed files with 76 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -6,9 +6,6 @@

/**
* 下载注解。
* 标注了该注解的方法将被拦截。
* 因为该注解将替换返回值,
* 所以请标注在 Controller 的 Mapping 方法上。
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
Original file line number Diff line number Diff line change
@@ -2,14 +2,16 @@

import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.exception.DownloadException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
* {@link SourceCompressorAdapter} 的默认实现。
*/
@AllArgsConstructor
@Getter
@RequiredArgsConstructor
public class DefaultSourceCompressorAdapter implements SourceCompressorAdapter {

/**
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.github.linyuzai.download.core.compress;

import com.github.linyuzai.download.core.web.ContentType;
import lombok.*;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

/**
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

import com.github.linyuzai.download.core.concept.Part;
import com.github.linyuzai.download.core.source.Source;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.io.IOException;
import java.io.InputStream;
@@ -12,13 +13,14 @@
/**
* 不压缩。
*/
@AllArgsConstructor
@Getter
@RequiredArgsConstructor
public class NoCompression implements Compression {

/**
* 单个的 {@link Source}
*/
protected Source source;
protected final Source source;

/**
* 直接返回 {@link Source#getInputStream()}。
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.linyuzai.download.core.concept;

import com.github.linyuzai.download.core.event.DownloadCompletedEvent;
import com.github.linyuzai.download.core.event.DownloadStartedEvent;
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.context.DownloadContextFactory;
import com.github.linyuzai.download.core.event.DownloadCompletedEvent;
import com.github.linyuzai.download.core.event.DownloadEventPublisher;
import com.github.linyuzai.download.core.event.DownloadStartedEvent;
import com.github.linyuzai.download.core.handler.DownloadHandler;
import com.github.linyuzai.download.core.options.DownloadOptions;
import lombok.Getter;
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.linyuzai.download.core.context;

import com.github.linyuzai.download.core.options.DownloadOptions;

/**
* 下载上下文。
*
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.linyuzai.download.core.event;

import com.github.linyuzai.download.core.context.DownloadContext;
import lombok.*;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

/**
* 附带了 {@link DownloadContext} 的 {@link DownloadEvent}。
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.linyuzai.download.core.event;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

/**
* {@link DownloadEventPublisher} 的委派类,用于临时的组合监听器调用。
*/
@AllArgsConstructor
@Getter
@RequiredArgsConstructor
public class DownloadEventPublisherDelegate implements DownloadEventPublisher {

/**
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
import com.github.linyuzai.download.core.annotation.Download;
import com.github.linyuzai.download.core.compress.*;
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.event.DownloadLifecycleListener;
import com.github.linyuzai.download.core.event.DownloadEventPublisher;
import com.github.linyuzai.download.core.event.DownloadLifecycleListener;
import com.github.linyuzai.download.core.handler.DownloadHandler;
import com.github.linyuzai.download.core.handler.DownloadHandlerChain;
import com.github.linyuzai.download.core.options.DownloadOptions;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.linyuzai.download.core.handler.impl;

import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.event.DownloadLifecycleListener;
import com.github.linyuzai.download.core.event.DownloadEventPublisher;
import com.github.linyuzai.download.core.event.DownloadLifecycleListener;
import com.github.linyuzai.download.core.handler.DownloadHandler;
import com.github.linyuzai.download.core.handler.DownloadHandlerChain;
import com.github.linyuzai.download.core.options.DownloadOptions;
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@
import com.github.linyuzai.download.core.concept.Part;
import com.github.linyuzai.download.core.concept.Resource;
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.event.DownloadLifecycleListener;
import com.github.linyuzai.download.core.event.DownloadEventPublisher;
import com.github.linyuzai.download.core.event.DownloadLifecycleListener;
import com.github.linyuzai.download.core.handler.DownloadHandler;
import com.github.linyuzai.download.core.handler.DownloadHandlerChain;
import com.github.linyuzai.download.core.options.DownloadOptions;
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
/**
* 下载日志抽象类。
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public abstract class LoggingDownloadEventListener implements DownloadEventListener {
@@ -22,19 +24,13 @@ public abstract class LoggingDownloadEventListener implements DownloadEventListe
/**
* 标签
*/
@Getter
@Setter
private String tag = "Download";

/**
* 用于标签长度对齐
*/
@Getter
@Setter
private int tagLength = 8;

@Getter
@Setter
private boolean enabled;

@Override
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.linyuzai.download.core.log;

import com.github.linyuzai.download.core.event.DownloadCompletedEvent;
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.event.DownloadCompletedEvent;
import com.github.linyuzai.download.core.load.SourceLoadingProgressEvent;
import com.github.linyuzai.download.core.web.ResponseWritingProgressEvent;
import com.github.linyuzai.download.core.write.AbstractProgressEvent;
@@ -20,6 +20,8 @@
/**
* 进度计算日志,包括加载进度,压缩进度,响应写入进度。
*/
@Getter
@Setter
@AllArgsConstructor
public class ProgressCalculationLogger extends LoggingDownloadEventListener {

@@ -31,15 +33,11 @@ public class ProgressCalculationLogger extends LoggingDownloadEventListener {
/**
* 打印间隔
*/
@Getter
@Setter
private Duration duration;

/**
* 是否使用百分比数据
*/
@Getter
@Setter
private boolean percentage;

public ProgressCalculationLogger() {
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@
import com.github.linyuzai.download.core.compress.CompressionCacheDeletedEvent;
import com.github.linyuzai.download.core.compress.CompressionReleasedEvent;
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.event.DownloadStartedEvent;
import com.github.linyuzai.download.core.event.DownloadContextEvent;
import com.github.linyuzai.download.core.event.DownloadStartedEvent;
import com.github.linyuzai.download.core.load.AbstractLoadSourceEvent;
import com.github.linyuzai.download.core.source.AbstractCreateSourceEvent;
import com.github.linyuzai.download.core.source.Source;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.linyuzai.download.core.log;

import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.event.DownloadCompletedEvent;
import com.github.linyuzai.download.core.event.DownloadStartedEvent;
import com.github.linyuzai.download.core.context.DownloadContext;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Original file line number Diff line number Diff line change
@@ -2,14 +2,16 @@

import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.exception.DownloadException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
* {@link SourceFactoryAdapter} 的默认实现。
*/
@AllArgsConstructor
@Getter
@RequiredArgsConstructor
public class DefaultSourceFactoryAdapter implements SourceFactoryAdapter {

/**
Original file line number Diff line number Diff line change
@@ -3,9 +3,8 @@
import com.github.linyuzai.download.core.concept.AbstractPart;
import com.github.linyuzai.download.core.concept.Part;
import com.github.linyuzai.download.core.web.ContentType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.RequiredArgsConstructor;

import java.io.File;
import java.io.FileInputStream;
@@ -21,23 +20,23 @@
* 支持 {@link File} 的 {@link Part}。
*/
@Getter
@AllArgsConstructor
@RequiredArgsConstructor
public class FilePart extends AbstractPart {

/**
* 文件
*/
protected File file;
protected final File file;

/**
* 名称
*/
protected String name;
protected final String name;

/**
* 路径
*/
protected String path;
protected final String path;

/**
* 如果 {@link File#isFile()} 则返回 {@link FileInputStream},
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.source.Source;
import com.github.linyuzai.download.core.source.file.EmptyInputStream;
import lombok.*;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.io.InputStream;
import java.nio.charset.Charset;
Original file line number Diff line number Diff line change
@@ -3,9 +3,7 @@
import com.github.linyuzai.download.core.concept.Resource;
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.web.Range;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import lombok.*;

import java.io.BufferedReader;
import java.io.InputStream;
@@ -17,6 +15,8 @@
* 使用缓冲区的写入器 / Writer using buffer
* 默认缓冲区为1M / The default buffer is 1M
*/
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class BufferedDownloadWriter implements DownloadWriter {
Original file line number Diff line number Diff line change
@@ -3,16 +3,16 @@
import com.github.linyuzai.download.core.concept.Resource;
import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.exception.DownloadException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
* {@link DownloadWriterAdapter} 的默认实现。
*/
@Getter
@AllArgsConstructor
@RequiredArgsConstructor
public class DefaultDownloadWriterAdapter implements DownloadWriterAdapter {

/**
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.linyuzai.download.autoconfigure;

import com.github.linyuzai.download.autoconfigure.event.ApplicationDownloadEventPublisher;
import com.github.linyuzai.download.autoconfigure.properties.DownloadProperties;
import com.github.linyuzai.download.autoconfigure.source.classpath.ClassPathPrefixSourceFactory;
import com.github.linyuzai.download.autoconfigure.source.classpath.ClassPathSourceFactory;
import com.github.linyuzai.download.autoconfigure.source.reactive.WebClientSourceFactory;
import com.github.linyuzai.download.core.cache.CacheNameGenerator;
import com.github.linyuzai.download.core.cache.CacheNameGeneratorInitializer;
@@ -9,8 +12,8 @@
import com.github.linyuzai.download.core.compress.SourceCompressor;
import com.github.linyuzai.download.core.compress.SourceCompressorAdapter;
import com.github.linyuzai.download.core.compress.zip.ZipSourceCompressor;
import com.github.linyuzai.download.core.context.*;
import com.github.linyuzai.download.autoconfigure.event.ApplicationDownloadEventPublisher;
import com.github.linyuzai.download.core.context.DefaultDownloadContextFactory;
import com.github.linyuzai.download.core.context.DownloadContextFactory;
import com.github.linyuzai.download.core.event.DownloadEventListener;
import com.github.linyuzai.download.core.event.DownloadEventPublisher;
import com.github.linyuzai.download.core.event.DownloadEventPublisherInitializer;
@@ -27,8 +30,6 @@
import com.github.linyuzai.download.core.source.DefaultSourceFactoryAdapter;
import com.github.linyuzai.download.core.source.SourceFactory;
import com.github.linyuzai.download.core.source.SourceFactoryAdapter;
import com.github.linyuzai.download.autoconfigure.source.classpath.ClassPathPrefixSourceFactory;
import com.github.linyuzai.download.autoconfigure.source.classpath.ClassPathSourceFactory;
import com.github.linyuzai.download.core.source.file.FilePrefixSourceFactory;
import com.github.linyuzai.download.core.source.file.FileSourceFactory;
import com.github.linyuzai.download.core.source.file.UserHomeSourceFactory;
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
import com.github.linyuzai.download.core.exception.DownloadException;
import com.github.linyuzai.download.core.options.DownloadOptions;
import com.github.linyuzai.download.core.source.Source;
import com.github.linyuzai.download.core.source.file.FileSource;
import lombok.Getter;
import lombok.Setter;
import org.aopalliance.intercept.MethodInterceptor;
Loading

0 comments on commit 1bfa48e

Please sign in to comment.