Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
add deleting file log
Browse files Browse the repository at this point in the history
  • Loading branch information
kosteman committed Dec 21, 2016
1 parent 94cab25 commit 540cb7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,60 @@
import ru.sbtqa.monte.media.Registry;

public class VideoRecorderImpl extends ru.sbtqa.monte.screenrecorder.ScreenRecorder implements VideoRecorder {

private static final Logger LOG = LoggerFactory.getLogger(VideoRecorderImpl.class);

private final String tempFilenameWithoutExtension = "currentRecording_" + System.currentTimeMillis();
private final File tempMovieFolder;

private String currentTempExtension;

public VideoRecorderImpl(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat,
Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder)
throws IOException, AWTException {
super(cfg, captureArea, fileFormat, screenFormat, mouseFormat, audioFormat, movieFolder);
tempMovieFolder = movieFolder;
}

@Override
protected File createMovieFile(Format fileFormat) throws IOException {
this.currentTempExtension = Registry.getInstance().getExtension(fileFormat);
String tempFile = getTempFileName();

File fileToWriteMovie = new File(tempFile);
if (fileToWriteMovie.exists()) {
LOG.info("File {} is deleting...", fileToWriteMovie.getAbsolutePath());
if (!fileToWriteMovie.delete()) {
LOG.error("Failed to remove temporary file {}", fileToWriteMovie.getAbsolutePath());
}
}

return fileToWriteMovie;
}

private String getTempFileName() {
return tempMovieFolder.getPath() + File.separator
+ tempFilenameWithoutExtension + "." + this.currentTempExtension;
}

@Override
public String saveAs(String path, String filename) throws IOException {
this.stop();

File tempFile = this.getCreatedMovieFiles().get(0);

File destFile = getDestinationFile(path, filename);
if (!tempFile.renameTo(destFile)) {
LOG.error("Failed to rename file {}", path + filename);
}
return destFile.getAbsolutePath();
}

private File getDestinationFile(String path, String filename) {
String destFolderSuffix = "";

return new File(path + destFolderSuffix + File.separator
+ filename + "." + this.currentTempExtension);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class VideoRecorderRuntimeException extends RuntimeException {

/**
*
* @param e TODO
* @param e a {@link java.lang.Throwable} object.
*/
public VideoRecorderRuntimeException(Throwable e) {
super(e);
Expand Down

0 comments on commit 540cb7c

Please sign in to comment.