Clean up various IntelliJ warnings
This commit is contained in:
parent
7df5a06cd1
commit
958c02e670
2 changed files with 36 additions and 33 deletions
|
|
@ -6,8 +6,12 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.forkalsrud.album.db.Chunk;
|
||||
|
|
@ -19,12 +23,12 @@ import org.forkalsrud.album.web.PictureScaler;
|
|||
|
||||
public class MovieCoder {
|
||||
|
||||
private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MovieCoder.class);
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MovieCoder.class);
|
||||
|
||||
private String ffmpegExecutable;
|
||||
private String mplayerExecutable;
|
||||
private PictureScaler pictureScaler;
|
||||
private HashMap<String, EncodingProcess> currentEncodings = new HashMap<>();
|
||||
private final PictureScaler pictureScaler;
|
||||
private final HashMap<String, EncodingProcess> currentEncodings = new HashMap<>();
|
||||
|
||||
public MovieCoder(PictureScaler pictureScaler) {
|
||||
this.pictureScaler = pictureScaler;
|
||||
|
|
@ -52,12 +56,11 @@ public class MovieCoder {
|
|||
return temp;
|
||||
}
|
||||
|
||||
private void deleteTempDirectory(File dir) {
|
||||
for (File sub : dir.listFiles()) {
|
||||
if (sub.isDirectory()) {
|
||||
deleteTempDirectory(sub);
|
||||
private void deleteTempDirectory(File dir) throws IOException {
|
||||
try (Stream<Path> s = Files.walk(dir.toPath())) {
|
||||
if (!s.allMatch(f -> f.toFile().delete())) {
|
||||
throw new IOException("problem deleting " + dir);
|
||||
}
|
||||
sub.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,11 +86,11 @@ public class MovieCoder {
|
|||
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @param file the file to encode
|
||||
* @param thumbnail
|
||||
* @param targetSize
|
||||
* @param key
|
||||
* @return
|
||||
* @return a handle to the encoding process
|
||||
*/
|
||||
private synchronized EncodingProcess submitEncodingJob(File file,
|
||||
Thumbnail thumbnail, Dimension targetSize, String key, MovieDatabase movieDb) {
|
||||
|
|
@ -104,19 +107,19 @@ public class MovieCoder {
|
|||
class EncodingProcess implements Runnable, FlvFilter.FlvReceiver {
|
||||
|
||||
private final int chunkSize = 4 * 65536;
|
||||
private File file;
|
||||
private Dimension targetSize;
|
||||
private final File file;
|
||||
private final Dimension targetSize;
|
||||
private Chunk currentChunk = null;
|
||||
private int chunkPos;
|
||||
private int remainingCapacity;
|
||||
private volatile int chunkInProgress = 0;
|
||||
private final AtomicInteger chunkInProgress;
|
||||
private volatile int chunkAvailable = 0;
|
||||
private FlvFilter filter;
|
||||
private String dbKey;
|
||||
private long fileTimestamp;
|
||||
private int orientation;
|
||||
private final FlvFilter filter;
|
||||
private final String dbKey;
|
||||
private final long fileTimestamp;
|
||||
private final int orientation;
|
||||
private volatile boolean done = false;
|
||||
private MovieDatabase movieDb;
|
||||
private final MovieDatabase movieDb;
|
||||
|
||||
|
||||
public EncodingProcess(File file, Thumbnail thumbnail, Dimension size, MovieDatabase movieDb) {
|
||||
|
|
@ -126,6 +129,7 @@ public class MovieCoder {
|
|||
this.dbKey = key(file, targetSize);
|
||||
FlvMetadata extraMeta = new FlvMetadata();
|
||||
extraMeta.setDuration(thumbnail.getDuration());
|
||||
this.chunkInProgress = new AtomicInteger(0);
|
||||
this.filter = new FlvFilter(this, extraMeta);
|
||||
this.orientation = thumbnail.getOrientation();
|
||||
this.movieDb = movieDb;
|
||||
|
|
@ -267,7 +271,7 @@ public class MovieCoder {
|
|||
chunk0.bits = data;
|
||||
log.info("Writing {} seq 0 ({}) {}", dbKey, chunkInProgress, data.length);
|
||||
movieDb.store(dbKey, 0, chunk0);
|
||||
notifyListeners(chunkInProgress);
|
||||
notifyListeners(chunkInProgress.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -297,7 +301,7 @@ public class MovieCoder {
|
|||
|
||||
private void startNewChunk() {
|
||||
|
||||
this.chunkInProgress++;
|
||||
this.chunkInProgress.incrementAndGet();
|
||||
this.currentChunk = new Chunk(fileTimestamp, chunkSize, 0);
|
||||
this.chunkPos = 0;
|
||||
this.remainingCapacity = chunkSize;
|
||||
|
|
@ -306,10 +310,10 @@ public class MovieCoder {
|
|||
private void endChunk() {
|
||||
|
||||
log.info("store chunk {}", chunkInProgress);
|
||||
movieDb.store(dbKey, chunkInProgress, currentChunk);
|
||||
movieDb.store(dbKey, chunkInProgress.get(), currentChunk);
|
||||
log.info("Writing {} seq {} ({}) {}", dbKey, chunkInProgress, chunkInProgress, currentChunk.bits.length);
|
||||
currentChunk = null;
|
||||
notifyListeners(chunkInProgress);
|
||||
notifyListeners(chunkInProgress.get());
|
||||
}
|
||||
|
||||
private void endLastChunk() {
|
||||
|
|
@ -320,16 +324,16 @@ public class MovieCoder {
|
|||
// reallocate
|
||||
Chunk last = new Chunk(fileTimestamp, chunkPos, 0);
|
||||
System.arraycopy(currentChunk.bits, 0, last.bits, 0, chunkPos);
|
||||
movieDb.store(dbKey, chunkInProgress, last);
|
||||
movieDb.store(dbKey, chunkInProgress.get(), last);
|
||||
log.info("Writing {} seq {} ({}) {}", dbKey, chunkInProgress, chunkInProgress, last.bits.length);
|
||||
currentChunk = null;
|
||||
}
|
||||
}
|
||||
|
||||
class ErrorStreamPumper implements Runnable {
|
||||
static class ErrorStreamPumper implements Runnable {
|
||||
|
||||
private InputStream is;
|
||||
private String name;
|
||||
private final InputStream is;
|
||||
private final String name;
|
||||
|
||||
public ErrorStreamPumper(String processName, InputStream is) {
|
||||
this.name = processName;
|
||||
|
|
@ -338,12 +342,12 @@ public class MovieCoder {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
org.slf4j.Logger diag = org.slf4j.LoggerFactory.getLogger(this.name);
|
||||
org.slf4j.Logger diagnostic = org.slf4j.LoggerFactory.getLogger(this.name);
|
||||
try {
|
||||
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is));
|
||||
String line;
|
||||
while ((line = lnr.readLine()) != null) {
|
||||
diag.info(line);
|
||||
diagnostic.info(line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("stderr?", e);
|
||||
|
|
@ -398,11 +402,11 @@ public class MovieCoder {
|
|||
class VideoStreamer {
|
||||
|
||||
private int chunkNo = 0;
|
||||
private EncodingProcess ep;
|
||||
private final EncodingProcess ep;
|
||||
private Chunk chunk;
|
||||
private String key;
|
||||
private final String key;
|
||||
private boolean done = false;
|
||||
private MovieDatabase movieDb;
|
||||
private final MovieDatabase movieDb;
|
||||
|
||||
|
||||
private VideoStreamer(String key, EncodingProcess ep, Chunk chunk0, MovieDatabase movieDb) {
|
||||
|
|
|
|||
|
|
@ -312,8 +312,7 @@ public class AlbumServlet
|
|||
String query = req.getParameter("q");
|
||||
if (query != null && !"".equals(query.trim())) {
|
||||
SearchEngine search = new SearchEngine(entry);
|
||||
SearchResults results = search.search(query);
|
||||
contents = results;
|
||||
contents = search.search(query);
|
||||
} else {
|
||||
contents = entry;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue