forked from DataLinkDC/dinky
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add local resource (DataLinkDC#2717)
* fix log error * add local resoucrce manager * fix app * formte code
- Loading branch information
1 parent
3e1cbf4
commit e9c59e2
Showing
11 changed files
with
225 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
dinky-admin/src/main/java/org/dinky/service/resource/impl/LocalResourceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.dinky.service.resource.impl; | ||
|
||
import org.dinky.data.exception.BusException; | ||
import org.dinky.service.resource.BaseResourceManager; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import cn.hutool.core.io.FileUtil; | ||
import cn.hutool.core.io.IORuntimeException; | ||
import cn.hutool.core.io.IoUtil; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class LocalResourceManager implements BaseResourceManager { | ||
@Override | ||
public void remove(String path) { | ||
try { | ||
boolean isSuccess = FileUtil.del(getFilePath(path)); | ||
if (!isSuccess) { | ||
throw new BusException("remove file failed,reason unknown"); | ||
} | ||
} catch (IORuntimeException e) { | ||
log.error("remove file failed", e); | ||
throw new BusException(e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public void rename(String path, String newPath) { | ||
try { | ||
String newName = FileUtil.getName(newPath); | ||
FileUtil.rename(new File(getFilePath(path)), newName, true); | ||
} catch (Exception e) { | ||
log.error("rename file failed", e); | ||
throw new BusException(e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public void putFile(String path, MultipartFile file) { | ||
try { | ||
FileUtil.writeFromStream(file.getInputStream(), getFilePath(path)); | ||
} catch (IOException e) { | ||
log.error("putFile file failed", e); | ||
throw new BusException(e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public void putFile(String path, File file) { | ||
BufferedInputStream inputStream = FileUtil.getInputStream(file); | ||
FileUtil.writeFromStream(inputStream, getFilePath(path)); | ||
} | ||
|
||
@Override | ||
public String getFileContent(String path) { | ||
return IoUtil.readUtf8(readFile(path)); | ||
} | ||
|
||
@Override | ||
public InputStream readFile(String path) { | ||
return FileUtil.getInputStream(getFilePath(path)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.