diff --git a/docs/spring/cs858fd53a-3f01-11ee-a772-acde48001122.java b/docs/spring/cs858fd53a-3f01-11ee-a772-acde48001122.java new file mode 100644 index 00000000..6b5509de --- /dev/null +++ b/docs/spring/cs858fd53a-3f01-11ee-a772-acde48001122.java @@ -0,0 +1,135 @@ +package com.huifer.bigfile.services; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * 限流下载service + */ +@Service +public class LimiterFileService { + /** + * 下载计数器:记录有多少个下载请求 + */ + public static final AtomicInteger DOWNLOAD_NUM = new AtomicInteger(); + protected static final Logger log = LoggerFactory.getLogger(LimiterFileService.class); + /** + * 最大下载速度,单位:kb + */ + @Value("${max.download.speed}") + public int maxDownloadSpeed; + + + public void downloadBreak(String name, HttpServletRequest request, HttpServletResponse response) { + + + } + + + /** + * 限流下载 + * // TODO: 2019/9/2 下载暂停会出现异常 + * + * @param exportUrl 下载文件url + * @param speed 速度 + * @param response response + */ + public void downloadLimit(String exportUrl, int speed, HttpServletResponse response) { + OutputStream out = null; + String fileName = exportUrl.substring(exportUrl.lastIndexOf('/') + 1); + response.setContentType("application/octet-stream"); + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + int downloadSpeed = speed; + + try ( + InputStream fileInputStream = new FileInputStream(exportUrl); + ) { + BandwidthLimiter bandwidthLimiter = new BandwidthLimiter(downloadSpeed); + DownloadLimiter downloadLimiter = new DownloadLimiter(fileInputStream, bandwidthLimiter); + + out = response.getOutputStream(); + int len = 0; + while ((len = downloadLimiter.read()) != -1) { + out.write(len); + bandwidthLimiter.setMaxRate(speed); + } + out.flush(); + out.close(); + downloadLimiter.close(); + } catch (IOException e) { + log.error("下载失败={}", e); + } finally { + closeStream(out, null); + } + } + + /** + * 限流下载 + * + * @param exportUrl 下载文件url + * @param response response + */ + public void downloadLimit(String exportUrl, HttpServletResponse response) { + DOWNLOAD_NUM.incrementAndGet(); + OutputStream out = null; + DownloadLimiter downloadLimiter = null; + String fileName = exportUrl.substring(exportUrl.lastIndexOf('/') + 1); + response.setContentType("application/octet-stream"); + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + + try (InputStream fileInputStream = new FileInputStream(exportUrl);) { + int downloadSpeed = maxDownloadSpeed / DOWNLOAD_NUM.get(); + BandwidthLimiter bandwidthLimiter = new BandwidthLimiter(downloadSpeed); + downloadLimiter = new DownloadLimiter(fileInputStream, bandwidthLimiter); + out = response.getOutputStream(); + int len = 0; + while ((len = downloadLimiter.read()) != -1) { + out.write(len); + bandwidthLimiter.setMaxRate(maxDownloadSpeed / DOWNLOAD_NUM.get()); + } + out.flush(); + out.close(); + downloadLimiter.close(); + } catch (IOException e) { + log.error("下载失败={}", e); + } finally { + closeStream(out, downloadLimiter); + } + DOWNLOAD_NUM.decrementAndGet(); + } + + /** + * 关闭流 + * + * @param out OutputStream + * @param downloadLimiter DownloadLimiter + */ + protected void closeStream(OutputStream out, DownloadLimiter downloadLimiter) { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + log.error("输出流关闭失败{}", e); + } + } + if (downloadLimiter != null) { + try { + downloadLimiter.close(); + } catch (IOException e) { + log.error("下载限流关闭失败={}", e); + } + } + } + + +} diff --git a/docs/spring/cs85d051b4-3f01-11ee-a772-acde48001122.java b/docs/spring/cs85d051b4-3f01-11ee-a772-acde48001122.java new file mode 100644 index 00000000..248c97b8 --- /dev/null +++ b/docs/spring/cs85d051b4-3f01-11ee-a772-acde48001122.java @@ -0,0 +1,93 @@ +/** + * Copyright 2009-2019 the original author or authors. + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.mapping;
+
+import org.apache.ibatis.builder.InitializingObject;
+import org.apache.ibatis.cache.Cache;
+import org.apache.ibatis.cache.CacheException;
+import org.apache.ibatis.cache.impl.PerpetualCache;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+
+import static com.googlecode.catchexception.apis.BDDCatchException.caughtException;
+import static com.googlecode.catchexception.apis.BDDCatchException.when;
+import static org.assertj.core.api.BDDAssertions.then;
+
+class CacheBuilderTest {
+
+ @Test
+ void testInitializing() {
+ InitializingCache cache = unwrap(new CacheBuilder("test").implementation(InitializingCache.class).build());
+
+ Assertions.assertThat(cache.initialized).isTrue();
+ }
+
+ @Test
+ void testInitializingFailure() {
+ when(() -> new CacheBuilder("test").implementation(InitializingFailureCache.class).build());
+ then(caughtException()).isInstanceOf(CacheException.class)
+ .hasMessage("Failed cache initialization for 'test' on 'org.apache.ibatis.mapping.CacheBuilderTest$InitializingFailureCache'");
+ }
+
+ @SuppressWarnings("unchecked")
+ private
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.type;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class EnumOrdinalTypeHandlerTest extends BaseTypeHandlerTest {
+
+ private static final TypeHandler
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.binding;
+
+public interface WrongNamespaceMapper {
+
+ void get();
+
+}
diff --git a/docs/spring/cs86c36e3a-3f01-11ee-a772-acde48001122.java b/docs/spring/cs86c36e3a-3f01-11ee-a772-acde48001122.java
new file mode 100644
index 00000000..7825daef
--- /dev/null
+++ b/docs/spring/cs86c36e3a-3f01-11ee-a772-acde48001122.java
@@ -0,0 +1,125 @@
+/**
+ * Copyright 2009-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.binding;
+
+import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
+import org.apache.ibatis.io.ResolverUtil;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.SqlSession;
+
+import java.util.*;
+
+/**
+ * @author Clinton Begin
+ * @author Eduardo Macarron
+ * @author Lasse Voss
+ */
+public class MapperRegistry {
+
+ private final Configuration config;
+ private final Map
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.submitted.call_setters_on_nulls;
+
+public class User {
+
+ public boolean nullReceived;
+ private Integer id;
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ if (name == null) {
+ nullReceived = true;
+ }
+ this.name = name;
+ }
+}
diff --git a/docs/spring/cs873debce-3f01-11ee-a772-acde48001122.java b/docs/spring/cs873debce-3f01-11ee-a772-acde48001122.java
new file mode 100644
index 00000000..8d13734e
--- /dev/null
+++ b/docs/spring/cs873debce-3f01-11ee-a772-acde48001122.java
@@ -0,0 +1,16 @@
+package com.huifer.design.factory;
+
+/**
+ * Title : MengNiu Description : 蒙牛
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.domain.blog;
+
+public class DraftPost extends Post {
+}
diff --git a/docs/spring/cs87b3a8c8-3f01-11ee-a772-acde48001122.java b/docs/spring/cs87b3a8c8-3f01-11ee-a772-acde48001122.java
new file mode 100644
index 00000000..07f69430
--- /dev/null
+++ b/docs/spring/cs87b3a8c8-3f01-11ee-a772-acde48001122.java
@@ -0,0 +1,16 @@
+package com.huifer.security;
+
+import com.huifer.security.properties.SecurityProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 描述:
+ *
+ * @author: huifer
+ * @date: 2019-11-17
+ */
+@Configuration
+@EnableConfigurationProperties(SecurityProperties.class)
+public class SecurityCoreConfig {
+}
diff --git a/docs/spring/cs87ed6a18-3f01-11ee-a772-acde48001122.java b/docs/spring/cs87ed6a18-3f01-11ee-a772-acde48001122.java
new file mode 100644
index 00000000..cfd8c4f8
--- /dev/null
+++ b/docs/spring/cs87ed6a18-3f01-11ee-a772-acde48001122.java
@@ -0,0 +1,20 @@
+package com.huifer.security.properties;
+
+/**
+ * 描述:
+ *
+ * @author: huifer
+ * @date: 2019-11-17
+ */
+public enum LoginType {
+
+ /**
+ * json
+ */
+ JSON,
+ /**
+ * 跳转
+ */
+ REDIRECT,
+ ;
+}