aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/util
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-06-29 14:03:04 +0300
committerGravatar Vitaly Takmazov2017-06-29 14:03:04 +0300
commit02723131139806c761539a42a5fa80b68ecadee8 (patch)
treeca66f22993908758385f708eb2da4e4aeb20510a /juick-server/src/main/java/com/juick/server/util
parent4cc4b08f4377b7db697abdb533c625da608eb3d3 (diff)
project structure: split server into jdbc + web
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/util')
-rw-r--r--juick-server/src/main/java/com/juick/server/util/HttpBadRequestException.java15
-rw-r--r--juick-server/src/main/java/com/juick/server/util/HttpForbiddenException.java16
-rw-r--r--juick-server/src/main/java/com/juick/server/util/HttpNotFoundException.java15
-rw-r--r--juick-server/src/main/java/com/juick/server/util/HttpUtils.java112
-rw-r--r--juick-server/src/main/java/com/juick/server/util/ImageUtils.java66
5 files changed, 0 insertions, 224 deletions
diff --git a/juick-server/src/main/java/com/juick/server/util/HttpBadRequestException.java b/juick-server/src/main/java/com/juick/server/util/HttpBadRequestException.java
deleted file mode 100644
index 1ba1aecb..00000000
--- a/juick-server/src/main/java/com/juick/server/util/HttpBadRequestException.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.juick.server.util;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Created by vt on 24/11/2016.
- */
-@ResponseStatus(value = HttpStatus.BAD_REQUEST)
-public class HttpBadRequestException extends RuntimeException {
- public HttpBadRequestException() {
- super(StringUtils.EMPTY, null, false, false);
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/util/HttpForbiddenException.java b/juick-server/src/main/java/com/juick/server/util/HttpForbiddenException.java
deleted file mode 100644
index 733453ba..00000000
--- a/juick-server/src/main/java/com/juick/server/util/HttpForbiddenException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.juick.server.util;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Created by vt on 24/11/2016.
- */
-@ResponseStatus(value = HttpStatus.FORBIDDEN)
-public class HttpForbiddenException extends RuntimeException {
- public HttpForbiddenException() {
- super(StringUtils.EMPTY, null, false, false);
- }
-
-}
diff --git a/juick-server/src/main/java/com/juick/server/util/HttpNotFoundException.java b/juick-server/src/main/java/com/juick/server/util/HttpNotFoundException.java
deleted file mode 100644
index 942d90e2..00000000
--- a/juick-server/src/main/java/com/juick/server/util/HttpNotFoundException.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.juick.server.util;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Created by vt on 24/11/2016.
- */
-@ResponseStatus(value = HttpStatus.NOT_FOUND)
-public class HttpNotFoundException extends RuntimeException {
- public HttpNotFoundException() {
- super(StringUtils.EMPTY, null, false, false);
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/util/HttpUtils.java b/juick-server/src/main/java/com/juick/server/util/HttpUtils.java
deleted file mode 100644
index 31a68962..00000000
--- a/juick-server/src/main/java/com/juick/server/util/HttpUtils.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Juick
- * Copyright (C) 2008-2011, Ugnich Anton
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package com.juick.server.util;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.UUID;
-
-/**
- *
- * @author Ugnich Anton
- */
-public class HttpUtils {
- private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
-
- public static String receiveMultiPartFile(MultipartFile attach, String tmpDir) {
- if (attach !=null && !attach.isEmpty()) {
- String partname = attach.getOriginalFilename();
- if (partname != null && partname.length() > 0) {
- String attachmentType = partname.substring(partname.length() - 3).toLowerCase();
- if (attachmentType.equals("jpg") || attachmentType.equals("peg") || attachmentType.equals("png")) {
- if (attachmentType.equals("peg")) {
- attachmentType = "jpg";
- }
- String attachmentFName = DigestUtils.md5Hex(UUID.randomUUID().toString()) + "." + attachmentType;
- try {
- Files.write(Paths.get(tmpDir, attachmentFName),
- attach.getBytes());
- return attachmentFName;
- } catch (IOException e) {
- logger.warn("file receive error", e);
- }
- }
- }
- }
- return StringUtils.EMPTY;
- }
- public static String downloadImage(URL url, String tmpDir) throws Exception {
- String attachmentFName = null;
- Exception ex = null;
-
- InputStream is = null;
- FileOutputStream fos = null;
- try {
- URLConnection urlConn = url.openConnection();
- is = urlConn.getInputStream();
- String mime = urlConn.getContentType();
-
- String attachmentType;
- if (mime != null && mime.equals("image/jpeg")) {
- attachmentType = "jpg";
- } else if (mime != null && mime.equals("image/png")) {
- attachmentType = "png";
- } else {
- throw new Exception("Wrong file type");
- }
-
- attachmentFName = DigestUtils.md5Hex(UUID.randomUUID().toString()) + "." + attachmentType;
- fos = new FileOutputStream(Paths.get(tmpDir, attachmentFName).toString());
- byte[] buffer = new byte[10240];
- int len;
- while ((len = is.read(buffer)) > 0) {
- fos.write(buffer, 0, len);
- }
- } catch (Exception e) {
- ex = e;
- attachmentFName = null;
- } finally {
- try {
- if (is != null) {
- is.close();
- }
- } finally {
- if (fos != null) {
- fos.close();
- }
- }
- }
-
- if (ex != null) {
- throw ex;
- } else {
- return attachmentFName;
- }
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/util/ImageUtils.java b/juick-server/src/main/java/com/juick/server/util/ImageUtils.java
deleted file mode 100644
index 61677750..00000000
--- a/juick-server/src/main/java/com/juick/server/util/ImageUtils.java
+++ /dev/null
@@ -1,66 +0,0 @@
-
-package com.juick.server.util;
-
-import org.apache.commons.io.FilenameUtils;
-import org.imgscalr.Scalr;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-
-public class ImageUtils {
-
- /**
- * Move attached image from temp folder to image folder.
- * Create preview images in corresponding folders.
- *
- * @param tempFilename Name of the image file in temp folder.
- * @param outputFilename Name that will be used in in image folder.
- * @param tmpDir Path string for the temp folder.
- * @param imgDir Path string for the image folder.
- */
- public static void saveImageWithPreviews(String tempFilename, String outputFilename, String tmpDir, String imgDir)
- throws IOException {
- String ext = FilenameUtils.getExtension(outputFilename);
-
- Path outputImagePath = Paths.get(imgDir, "p", outputFilename);
- Files.move(Paths.get(tmpDir, tempFilename), outputImagePath);
- BufferedImage originalImage = ImageIO.read(outputImagePath.toFile());
-
- int width = originalImage.getWidth();
- int height = originalImage.getHeight();
- int maxDimension = (width > height) ? width : height;
- BufferedImage image1024 = (maxDimension > 1024) ? Scalr.resize(originalImage, 1024) : originalImage;
- BufferedImage image0512 = (maxDimension > 512) ? Scalr.resize(originalImage, 512) : originalImage;
- BufferedImage image0160 = (maxDimension > 160) ? Scalr.resize(originalImage, 160) : originalImage;
- ImageIO.write(image1024, ext, Paths.get(imgDir, "photos-1024", outputFilename).toFile());
- ImageIO.write(image0512, ext, Paths.get(imgDir, "photos-512", outputFilename).toFile());
- ImageIO.write(image0160, ext, Paths.get(imgDir, "ps", outputFilename).toFile());
- }
-
- /**
- * Save new avatar in all required sizes.
- *
- * @param tempFilename Name of the image file in temp folder.
- * @param uid User id that is used to build image file names.
- * @param tmpDir Path string for the temp folder.
- * @param imgDir Path string for the image folder.
- */
- public static void saveAvatar(String tempFilename, int uid, String tmpDir, String imgDir)
- throws IOException {
- String ext = FilenameUtils.getExtension(tempFilename);
- String originalName = String.format("%s.%s", uid, ext);
- Path originalPath = Paths.get(imgDir, "ao", originalName);
- Files.move(Paths.get(tmpDir, tempFilename), originalPath, StandardCopyOption.REPLACE_EXISTING);
- BufferedImage originalImage = ImageIO.read(originalPath.toFile());
-
- String targetExt = "png";
- String targetName = String.format("%s.%s", uid, targetExt);
- ImageIO.write(Scalr.resize(originalImage, 96), targetExt, Paths.get(imgDir, "a", targetName).toFile());
- ImageIO.write(Scalr.resize(originalImage, 32), targetExt, Paths.get(imgDir, "as", targetName).toFile());
- }
-} \ No newline at end of file