esoe
1 year ago
34 changed files with 296 additions and 31 deletions
@ -1,8 +1,17 @@
@@ -1,8 +1,17 @@
|
||||
# Storage-service |
||||
Сервис обмена файлами большого размера |
||||
|
||||
## API |
||||
# Realization |
||||
Файлы хранятся не в базе данных, а в самостоятельном хранилице на сервере, |
||||
в базе хранятся адреса файлов, их описания, |
||||
|
||||
|
||||
# API |
||||
- getFile |
||||
- postFile |
||||
- deleteFile |
||||
- listFiles |
||||
- listFiles |
||||
|
||||
# Servlets |
||||
|
||||
- viewFile |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
package ru.molokoin.storage.beans; |
||||
|
||||
import java.io.ByteArrayInputStream; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.util.Arrays; |
||||
import java.util.HashMap; |
||||
import java.util.Set; |
||||
import java.util.stream.Collectors; |
||||
import java.util.stream.Stream; |
||||
|
||||
import ru.molokoin.storage.entities.ContentEntity; |
||||
|
||||
/** |
||||
* Методы работы с данными на жестком диске |
||||
*/ |
||||
public class HardDrive { |
||||
public static String root = "/srv/apps/home/exchange"; |
||||
|
||||
public static String getRoot() { |
||||
return root; |
||||
} |
||||
public static void setRoot(String root) { |
||||
HardDrive.root = root; |
||||
} |
||||
/** |
||||
* Метод, возвращающий список файлов в корне хранилища приложения |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
public static Set<String> listFiles(String path) throws IOException{ |
||||
Stream<Path> stream = Files.list(Paths.get(path)); |
||||
Set<String> list = stream |
||||
.filter(file -> !Files.isDirectory(file)) |
||||
.map(Path::getFileName) |
||||
.map(Path::toString) |
||||
.collect(Collectors.toSet()); |
||||
stream.close(); |
||||
return list; |
||||
} |
||||
|
||||
private static HashMap<String, Boolean> getMap(String path) throws IOException{ |
||||
Stream<Path> stream = Files.list(Paths.get(path)); |
||||
HashMap<String, Boolean> map = new HashMap<>(); |
||||
return map; |
||||
} |
||||
|
||||
|
||||
public static void showFiles(File[] files) { |
||||
for (File file : files) { |
||||
if (file.isDirectory()) { |
||||
System.out.println("Directory: " + file.getAbsolutePath()); |
||||
showFiles(file.listFiles()); // Calls same method again.
|
||||
} else { |
||||
System.out.println("File: " + file.getAbsolutePath()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static Path getFileById(int id) throws IOException{ |
||||
Path path = null; |
||||
Set<String> set = listFiles(root); |
||||
int i = 0; |
||||
for (String s : set) { |
||||
i++; |
||||
System.out.println("CURRENT FILE >> " + s); |
||||
if (i == id){ |
||||
path = Paths.get(s); |
||||
System.out.println("SUCCESS >> " + path.toString()); |
||||
} |
||||
} |
||||
return path; |
||||
} |
||||
|
||||
} |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemalocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"> |
||||
<persistence-unit name="Storage" transaction-type="JTA"> |
||||
<persistence-unit name="default" transaction-type="JTA"> |
||||
<description>Подключение к базе molokoin.ru:3306/home</description> |
||||
<jta-data-source>java:/home</jta-data-source> |
||||
<class>ru.molokoin.storage.entities.ContentEntity</class> |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemalocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"> |
||||
<persistence-unit name="Storage" transaction-type="JTA"> |
||||
<persistence-unit name="default" transaction-type="JTA"> |
||||
<description>Подключение к базе molokoin.ru:3306/home</description> |
||||
<jta-data-source>java:/home</jta-data-source> |
||||
<class>ru.molokoin.storage.entities.ContentEntity</class> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.8.5 |
||||
groupId=ru.molokoin |
||||
artifactId=storage |
||||
version=1.0 |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
ru\molokoin\storage\entities\ContentEntity.class |
||||
ru\molokoin\storage\beans\StorageFace.class |
||||
ru\molokoin\storage\api\RestStorageService.class |
||||
ru\molokoin\storage\api\RestConfig.class |
||||
ru\molokoin\storage\beans\HardDrive.class |
||||
ru\molokoin\storage\beans\Storage.class |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
C:\Users\Strannik\Documents\esoe\code\storage\src\main\java\ru\molokoin\storage\beans\Storage.java |
||||
C:\Users\Strannik\Documents\esoe\code\storage\src\main\java\ru\molokoin\storage\beans\StorageFace.java |
||||
C:\Users\Strannik\Documents\esoe\code\storage\src\main\java\ru\molokoin\storage\entities\ContentEntity.java |
||||
C:\Users\Strannik\Documents\esoe\code\storage\src\main\java\ru\molokoin\storage\api\RestConfig.java |
||||
C:\Users\Strannik\Documents\esoe\code\storage\src\main\java\ru\molokoin\storage\beans\HardDrive.java |
||||
C:\Users\Strannik\Documents\esoe\code\storage\src\main\java\ru\molokoin\storage\api\RestStorageService.java |
Binary file not shown.
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemalocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"> |
||||
<persistence-unit name="default" transaction-type="JTA"> |
||||
<description>Подключение к базе molokoin.ru:3306/home</description> |
||||
<jta-data-source>java:/home</jta-data-source> |
||||
<class>ru.molokoin.storage.entities.ContentEntity</class> |
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes> |
||||
</persistence-unit> |
||||
</persistence> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
<!DOCTYPE web-app PUBLIC |
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" |
||||
"http://java.sun.com/dtd/web-app_2_3.dtd" > |
||||
|
||||
<web-app> |
||||
<display-name>Archetype Created Web Application</display-name> |
||||
</web-app> |
Loading…
Reference in new issue