mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Tidy up [skip ci]
This commit is contained in:
@@ -33,7 +33,6 @@ import static org.alfresco.transform.base.fs.FileManager.deleteFile;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.transform.base.logging.LogEntry;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
/**
|
||||
|
@@ -31,7 +31,6 @@ import org.alfresco.transform.common.ExtensionService;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
@@ -44,7 +43,6 @@ import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static org.alfresco.transform.common.ExtensionService.getExtensionForMimetype;
|
||||
@@ -58,7 +56,6 @@ public class FileManager
|
||||
{
|
||||
public static final String SOURCE_FILE = "sourceFile";
|
||||
public static final String TARGET_FILE = "targetFile";
|
||||
private static final String FILENAME = "filename=";
|
||||
|
||||
public static File createSourceFile(HttpServletRequest request, InputStream inputStream, String sourceMimetype)
|
||||
{
|
||||
@@ -107,18 +104,6 @@ public class FileManager
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(Resource body, File file)
|
||||
{
|
||||
try
|
||||
{
|
||||
Files.copy(body.getInputStream(), file.toPath(), REPLACE_EXISTING);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(INSUFFICIENT_STORAGE, "Failed to store the source file", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Resource load(File file)
|
||||
{
|
||||
try
|
||||
@@ -141,22 +126,6 @@ public class FileManager
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFilenameFromContentDisposition(HttpHeaders headers)
|
||||
{
|
||||
String filename = "";
|
||||
String contentDisposition = headers.getFirst(CONTENT_DISPOSITION);
|
||||
if (contentDisposition != null)
|
||||
{
|
||||
String[] strings = contentDisposition.split("; *");
|
||||
filename = Arrays.stream(strings)
|
||||
.filter(s -> s.startsWith(FILENAME))
|
||||
.findFirst()
|
||||
.map(s -> s.substring(FILENAME.length()))
|
||||
.orElse("");
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
public static InputStream getMultipartFileInputStream(MultipartFile sourceMultipartFile)
|
||||
{
|
||||
InputStream inputStream;
|
||||
|
@@ -49,8 +49,6 @@ import org.springframework.http.HttpStatus;
|
||||
public final class LogEntry
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(LogEntry.class);
|
||||
// TODO allow ProbeTransform to find out if there are any transforms running longer than the max time.
|
||||
|
||||
private static final AtomicInteger count = new AtomicInteger(0);
|
||||
private static final Deque<LogEntry> log = new ConcurrentLinkedDeque<>();
|
||||
private static final int MAX_LOG_SIZE = 10;
|
||||
@@ -69,7 +67,6 @@ public final class LogEntry
|
||||
private final int id = count.incrementAndGet();
|
||||
private final long start = System.currentTimeMillis();
|
||||
private int statusCode;
|
||||
|
||||
private long durationStreamIn;
|
||||
private long durationTransform = -1;
|
||||
private long durationStreamOut = -1;
|
||||
@@ -149,14 +146,12 @@ public final class LogEntry
|
||||
currentLogEntry.get().options = options;
|
||||
}
|
||||
|
||||
public static long setStatusCodeAndMessage(HttpStatus status, String message)
|
||||
public static void setStatusCodeAndMessage(HttpStatus status, String message)
|
||||
{
|
||||
LogEntry logEntry = currentLogEntry.get();
|
||||
logEntry.statusCode = status.value();
|
||||
logEntry.message = message;
|
||||
logEntry.durationTransform = System.currentTimeMillis() - logEntry.start - logEntry.durationStreamIn;
|
||||
|
||||
return logEntry.durationTransform;
|
||||
}
|
||||
|
||||
public static long getTransformDuration()
|
||||
@@ -247,10 +242,9 @@ public final class LogEntry
|
||||
|
||||
private String size(long size)
|
||||
{
|
||||
// TODO fix numeric overflow in TB expression
|
||||
return size == -1 ? "" : size(size, "1 byte",
|
||||
new String[]{"bytes", " KB", " MB", " GB", " TB"},
|
||||
new long[]{1024, 1024 * 1024, 1024 * 1024 * 1024, 1024 * 1024 * 1024 * 1024, Long.MAX_VALUE});
|
||||
new long[]{1024, 1024 * 1024, 1024 * 1024 * 1024, 1024L * 1024 * 1024 * 1024, Long.MAX_VALUE});
|
||||
}
|
||||
|
||||
private String size(long size, String singleValue, String[] units, long[] dividers)
|
||||
|
Reference in New Issue
Block a user