From c38f17ab9fc2d791ae482a60047a602031a5aab7 Mon Sep 17 00:00:00 2001 From: zhourui Date: Fri, 29 Jul 2022 14:45:14 +0800 Subject: [PATCH] add index --- o2server/pom.xml | 4 ++-- .../x/base/core/project/config/Config.java | 11 +++++++++- .../project/connection/ConnectionAction.java | 7 +++--- .../x/base/core/project/tools/PathTools.java | 22 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/o2server/pom.xml b/o2server/pom.xml index 4e105024fd..860de33988 100644 --- a/o2server/pom.xml +++ b/o2server/pom.xml @@ -1106,7 +1106,7 @@ - + \ No newline at end of file diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java index 4af6a33ecc..066ae064c3 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java @@ -131,6 +131,7 @@ public class Config { public static final String DIR_JVM = "jvm"; public static final String DIR_LOCAL = "local"; public static final String DIR_LOCAL_BACKUP = "local/backup"; + public static final String DIR_LOCAL_REPOSITORY = "local/repository"; public static final String DIR_LOCAL_UPDATE = "local/update"; public static final String DIR_LOCAL_TEMP = "local/temp"; public static final String DIR_LOCAL_TEMP_CLASSES = "local/temp/classes"; @@ -312,7 +313,7 @@ public class Config { return SystemUtils.IS_OS_WINDOWS ? dir.resolve("bin/jmap.exe") : dir.resolve("bin/jmap"); } - public static File dir_local() throws Exception { + public static File dir_local() throws IOException, URISyntaxException { return new File(base(), DIR_LOCAL); } @@ -514,6 +515,14 @@ public class Config { return path; } + public static Path pathLocalRepository(boolean force) throws IOException, URISyntaxException { + Path path = Paths.get(base(), DIR_LOCAL_REPOSITORY); + if (!Files.exists(path) && force) { + Files.createDirectories(path); + } + return path; + } + public static synchronized void flush() { INSTANCE = null; } diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/connection/ConnectionAction.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/connection/ConnectionAction.java index 19b9c5db42..8ba741e142 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/connection/ConnectionAction.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/connection/ConnectionAction.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; @@ -82,7 +83,7 @@ public class ConnectionAction { int status = connection.getResponseCode(); if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM) { String redirect = connection.getHeaderField("Location"); - if(StringUtils.isNotBlank(redirect)) { + if (StringUtils.isNotBlank(redirect)) { connection.disconnect(); return getDelete(connectTimeout, readTimeout, redirect, method, heads); } @@ -375,8 +376,8 @@ public class ConnectionAction { IOUtils.write(StringTools.TWO_HYPHENS + boundary, output, StandardCharsets.UTF_8); IOUtils.write(StringTools.CRLF, output, StandardCharsets.UTF_8); IOUtils.write( - "Content-Disposition: form-data; name=\"" + filePart.getName().getBytes(StandardCharsets.UTF_8) - + "\"; filename=\"" + filePart.getFileName().getBytes(StandardCharsets.UTF_8) + "\"", + "Content-Disposition: form-data; name=\"" + filePart.getName() + "\"; filename=\"" + + URLEncoder.encode(filePart.getFileName(), StandardCharsets.UTF_8) + "\"", output, StandardCharsets.UTF_8); IOUtils.write(StringTools.CRLF, output, StandardCharsets.UTF_8); IOUtils.write("Content-Length: " + filePart.getBytes().length, output, StandardCharsets.UTF_8); diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/PathTools.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/PathTools.java index 777bc9707e..2605814975 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/PathTools.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/PathTools.java @@ -1,7 +1,12 @@ package com.x.base.core.project.tools; +import java.io.IOException; +import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import org.apache.commons.lang3.StringUtils; @@ -47,4 +52,21 @@ public class PathTools { return false; } + public static void copyDirectory(Path sourcePath, Path targetPath) throws IOException { + Files.walkFileTree(sourcePath, new SimpleFileVisitor() { + @Override + public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) + throws IOException { + Files.createDirectories(targetPath.resolve(sourcePath.relativize(dir))); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { + Files.copy(file, targetPath.resolve(sourcePath.relativize(file))); + return FileVisitResult.CONTINUE; + } + }); + } + } -- GitLab