-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Ogefest/feature/upload-file
Feature/upload file
- Loading branch information
Showing
4 changed files
with
76 additions
and
25 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
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,48 @@ | ||
package notepack.app.task; | ||
|
||
import notepack.app.domain.Note; | ||
import notepack.app.domain.Task; | ||
import notepack.app.domain.Workspace; | ||
import notepack.app.domain.exception.MessageError; | ||
import notepack.app.listener.WorkspaceListener; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
public class WorkspaceUploadFile extends BaseTask implements Task, TypeWorkspace { | ||
|
||
private File fileSource; | ||
private Workspace workspace; | ||
|
||
public WorkspaceUploadFile(Workspace workspace, File fileSource) { | ||
this.workspace = workspace; | ||
this.fileSource = fileSource; | ||
} | ||
|
||
@Override | ||
public void notify(WorkspaceListener listener) { | ||
} | ||
|
||
@Override | ||
public void backgroundWork() throws MessageError { | ||
|
||
byte[] bytesToSave; | ||
try { | ||
bytesToSave = Files.readAllBytes(fileSource.toPath()); | ||
|
||
Note n = new Note(workspace); | ||
n.setPath(workspace.getStorage().getBasePath() + File.separator + fileSource.getName()); | ||
n.setContents(bytesToSave); | ||
n.saveToStorage(); | ||
|
||
addTaskToQueue(new WorkspaceRefresh(workspace)); | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
throw new MessageError(e.getMessage(), e); | ||
} | ||
|
||
|
||
} | ||
} |
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