aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2018-02-02 16:38:55 +0500
committerAbyss777 <abyss@fox5.ru>2018-02-02 16:38:55 +0500
commitbec12783f99849131f80175731d00b3f7929e661 (patch)
tree185d255ed2b6d1069c48cc39f5ef0545e0574626
parentaf49fada37f21df9ed5ceb67504c45b714ec24d4 (diff)
downloadtraccar-server-bec12783f99849131f80175731d00b3f7929e661.tar.gz
traccar-server-bec12783f99849131f80175731d00b3f7929e661.tar.bz2
traccar-server-bec12783f99849131f80175731d00b3f7929e661.zip
Always initialize MediaManager
-rw-r--r--src/org/traccar/Context.java4
-rw-r--r--src/org/traccar/database/MediaManager.java33
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java8
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java8
5 files changed, 24 insertions, 33 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 3681cc2cc..09e3c619b 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -337,9 +337,7 @@ public final class Context {
ldapProvider = new LdapProvider(config);
}
- if (config.hasKey("media.path")) {
- mediaManager = new MediaManager(config);
- }
+ mediaManager = new MediaManager(config.getString("media.path"));
if (dataManager != null) {
usersManager = new UsersManager(dataManager);
diff --git a/src/org/traccar/database/MediaManager.java b/src/org/traccar/database/MediaManager.java
index 2c448a20c..482442735 100644
--- a/src/org/traccar/database/MediaManager.java
+++ b/src/org/traccar/database/MediaManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.traccar.database;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.traccar.Config;
import org.traccar.helper.Log;
import java.io.File;
@@ -34,8 +33,8 @@ public class MediaManager {
private String path;
- public MediaManager(Config config) {
- path = config.getString("media.path");
+ public MediaManager(String path) {
+ this.path = path;
}
private File createFile(String uniqueId, String name) throws IOException {
@@ -48,19 +47,21 @@ public class MediaManager {
}
public String writeFile(String uniqueId, ChannelBuffer buf, String extension) {
- int size = buf.readableBytes();
- String name = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()) + "." + extension;
- try (FileOutputStream output = new FileOutputStream(createFile(uniqueId, name));
- FileChannel fileChannel = output.getChannel()) {
- ByteBuffer byteBuffer = buf.toByteBuffer();
- int written = 0;
- while (written < size) {
- written += fileChannel.write(byteBuffer);
+ if (path != null) {
+ int size = buf.readableBytes();
+ String name = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()) + "." + extension;
+ try (FileOutputStream output = new FileOutputStream(createFile(uniqueId, name));
+ FileChannel fileChannel = output.getChannel()) {
+ ByteBuffer byteBuffer = buf.toByteBuffer();
+ int written = 0;
+ while (written < size) {
+ written += fileChannel.write(byteBuffer);
+ }
+ fileChannel.force(false);
+ return name;
+ } catch (IOException e) {
+ Log.warning(e);
}
- fileChannel.force(false);
- return name;
- } catch (IOException e) {
- Log.warning(e);
}
return null;
}
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index e1bb6f96c..4173b4d5b 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -703,11 +703,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
if (photo.writableBytes() > 0) {
sendPhotoRequest(channel, pictureId);
} else {
- if (Context.getMediaManager() != null) {
- Device device = Context.getDeviceManager().getById(deviceSession.getDeviceId());
- position.set(Position.KEY_IMAGE,
- Context.getMediaManager().writeFile(device.getUniqueId(), photo, "jpg"));
- }
+ Device device = Context.getDeviceManager().getById(deviceSession.getDeviceId());
+ position.set(
+ Position.KEY_IMAGE, Context.getMediaManager().writeFile(device.getUniqueId(), photo, "jpg"));
photos.remove(pictureId);
}
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index 4d42683b1..11e38194f 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -477,9 +477,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
- if (Context.getMediaManager() != null) {
- position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(imei, photo, "jpg"));
- }
+ position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(imei, photo, "jpg"));
photo = null;
return position;
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index cc0364094..fe62874b5 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -246,9 +246,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
int timeIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
buf.readerIndex(timeIndex + 12 + 2);
- if (Context.getMediaManager() != null) {
- position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(id, buf, "jpg"));
- }
+ position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(id, buf, "jpg"));
return position;
@@ -259,9 +257,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
- if (Context.getMediaManager() != null) {
- position.set(Position.KEY_AUDIO, Context.getMediaManager().writeFile(id, buf, "amr"));
- }
+ position.set(Position.KEY_AUDIO, Context.getMediaManager().writeFile(id, buf, "amr"));
return position;