mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-14 17:47:32 -05:00
* Fixing issue #353 Moved replaceIllegalCharacters method into StringUtils. Modified classes that write out to disk to call this method when saving a file. * Implementing suggested changes from comments in PR #448
This commit is contained in:
@@ -41,6 +41,7 @@ import io.github.dsheirer.source.SourceException;
|
|||||||
import io.github.dsheirer.source.SourceManager;
|
import io.github.dsheirer.source.SourceManager;
|
||||||
import io.github.dsheirer.source.SourceType;
|
import io.github.dsheirer.source.SourceType;
|
||||||
import io.github.dsheirer.source.config.SourceConfigTuner;
|
import io.github.dsheirer.source.config.SourceConfigTuner;
|
||||||
|
import io.github.dsheirer.util.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -286,7 +287,8 @@ public class ChannelProcessingManager implements ChannelEventListener
|
|||||||
channel.getDecodeConfiguration().getDecoderType()));
|
channel.getDecodeConfiguration().getDecoderType()));
|
||||||
|
|
||||||
/* Setup event logging */
|
/* Setup event logging */
|
||||||
List<Module> loggers = mEventLogManager.getLoggers(channel.getEventLogConfiguration(), channel.getName());
|
String cleanedChannelName = StringUtils.replaceIllegalCharacters(channel.getName());
|
||||||
|
List<Module> loggers = mEventLogManager.getLoggers(channel.getEventLogConfiguration(), cleanedChannelName);
|
||||||
|
|
||||||
if(!loggers.isEmpty())
|
if(!loggers.isEmpty())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ public abstract class EventLogger extends Module
|
|||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger(EventLogger.class);
|
private final static Logger mLog = LoggerFactory.getLogger(EventLogger.class);
|
||||||
|
|
||||||
private static final String[] ILLEGAL_FILENAME_CHARACTERS = {"#", "%", "&", "{", "}", "\\", "<", ">",
|
|
||||||
"*", "?", "/", " ", "$", "!", "'", "\"", ":", "@", "+", "`", "|", "="};
|
|
||||||
|
|
||||||
private Path mLogDirectory;
|
private Path mLogDirectory;
|
||||||
private String mFileNameSuffix;
|
private String mFileNameSuffix;
|
||||||
private String mLogFileName;
|
private String mLogFileName;
|
||||||
@@ -75,7 +72,7 @@ public abstract class EventLogger extends Module
|
|||||||
sb.append(File.separator);
|
sb.append(File.separator);
|
||||||
sb.append(TimeStamp.getTimeStamp("_"));
|
sb.append(TimeStamp.getTimeStamp("_"));
|
||||||
sb.append("_");
|
sb.append("_");
|
||||||
sb.append(replaceIllegalCharacters(mFileNameSuffix));
|
sb.append(mFileNameSuffix);
|
||||||
|
|
||||||
mLogFileName = sb.toString();
|
mLogFileName = sb.toString();
|
||||||
|
|
||||||
@@ -92,19 +89,6 @@ public abstract class EventLogger extends Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces any illegal filename characters in the proposed filename
|
|
||||||
*/
|
|
||||||
private String replaceIllegalCharacters(String filename)
|
|
||||||
{
|
|
||||||
for(String illegalCharacter : ILLEGAL_FILENAME_CHARACTERS)
|
|
||||||
{
|
|
||||||
filename = filename.replace(illegalCharacter, "_");
|
|
||||||
}
|
|
||||||
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
if(mLogFile != null)
|
if(mLogFile != null)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import io.github.dsheirer.sample.IOverflowListener;
|
|||||||
import io.github.dsheirer.sample.Listener;
|
import io.github.dsheirer.sample.Listener;
|
||||||
import io.github.dsheirer.sample.OverflowableTransferQueue;
|
import io.github.dsheirer.sample.OverflowableTransferQueue;
|
||||||
import io.github.dsheirer.sample.buffer.ReusableAudioPacket;
|
import io.github.dsheirer.sample.buffer.ReusableAudioPacket;
|
||||||
|
import io.github.dsheirer.util.StringUtils;
|
||||||
import io.github.dsheirer.util.ThreadPool;
|
import io.github.dsheirer.util.ThreadPool;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -203,14 +204,11 @@ public class RecorderManager implements Listener<ReusableAudioPacket>
|
|||||||
*/
|
*/
|
||||||
private String getFilePrefix(ReusableAudioPacket packet)
|
private String getFilePrefix(ReusableAudioPacket packet)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
Path baseFilePath = SystemProperties.getInstance().getApplicationFolder("recordings");
|
||||||
|
|
||||||
sb.append(SystemProperties.getInstance().getApplicationFolder("recordings"));
|
|
||||||
|
|
||||||
sb.append(File.separator);
|
|
||||||
|
|
||||||
Metadata metadata = packet.getMetadata();
|
Metadata metadata = packet.getMetadata();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(metadata.hasChannelConfigurationSystem() ? metadata.getChannelConfigurationSystem() + "_" : "");
|
sb.append(metadata.hasChannelConfigurationSystem() ? metadata.getChannelConfigurationSystem() + "_" : "");
|
||||||
sb.append(metadata.hasChannelConfigurationSite() ? metadata.getChannelConfigurationSite() + "_" : "");
|
sb.append(metadata.hasChannelConfigurationSite() ? metadata.getChannelConfigurationSite() + "_" : "");
|
||||||
sb.append(metadata.hasChannelConfigurationName() ? metadata.getChannelConfigurationName() + "_" : "");
|
sb.append(metadata.hasChannelConfigurationName() ? metadata.getChannelConfigurationName() + "_" : "");
|
||||||
@@ -225,7 +223,8 @@ public class RecorderManager implements Listener<ReusableAudioPacket>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
String cleanedFileName = StringUtils.replaceIllegalCharacters(sb.toString());
|
||||||
|
return baseFilePath.resolve(cleanedFileName).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path getRecordingBasePath()
|
public Path getRecordingBasePath()
|
||||||
@@ -240,7 +239,7 @@ public class RecorderManager implements Listener<ReusableAudioPacket>
|
|||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(getRecordingBasePath());
|
sb.append(getRecordingBasePath());
|
||||||
sb.append(File.separator).append(channelName).append("_baseband");
|
sb.append(File.separator).append(StringUtils.replaceIllegalCharacters(channelName)).append("_baseband");
|
||||||
|
|
||||||
return new ComplexBufferWaveRecorder(BASEBAND_SAMPLE_RATE, sb.toString());
|
return new ComplexBufferWaveRecorder(BASEBAND_SAMPLE_RATE, sb.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import io.github.dsheirer.module.Module;
|
|||||||
import io.github.dsheirer.sample.Listener;
|
import io.github.dsheirer.sample.Listener;
|
||||||
import io.github.dsheirer.sample.buffer.IReusableByteBufferListener;
|
import io.github.dsheirer.sample.buffer.IReusableByteBufferListener;
|
||||||
import io.github.dsheirer.sample.buffer.ReusableByteBuffer;
|
import io.github.dsheirer.sample.buffer.ReusableByteBuffer;
|
||||||
|
import io.github.dsheirer.util.StringUtils;
|
||||||
import io.github.dsheirer.util.TimeStamp;
|
import io.github.dsheirer.util.TimeStamp;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -119,8 +120,8 @@ public class BinaryRecorder extends Module implements IReusableByteBufferListene
|
|||||||
sb.append("_");
|
sb.append("_");
|
||||||
sb.append(mRecordingIdentifier.trim());
|
sb.append(mRecordingIdentifier.trim());
|
||||||
sb.append(".bits");
|
sb.append(".bits");
|
||||||
|
String cleaned = StringUtils.replaceIllegalCharacters(sb.toString());
|
||||||
return mBaseRecordingPath.resolve(sb.toString());
|
return mBaseRecordingPath.resolve(cleaned);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ public class ComplexBufferWaveRecorder extends Module implements IReusableComple
|
|||||||
sb.append("_");
|
sb.append("_");
|
||||||
sb.append(TimeStamp.getTimeStamp("_"));
|
sb.append(TimeStamp.getTimeStamp("_"));
|
||||||
sb.append(".wav");
|
sb.append(".wav");
|
||||||
|
|
||||||
mFile = Paths.get(sb.toString());
|
mFile = Paths.get(sb.toString());
|
||||||
|
|
||||||
mWriter = new ReusableBufferWaveWriter(mAudioFormat, mFile);
|
mWriter = new ReusableBufferWaveWriter(mAudioFormat, mFile);
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ package io.github.dsheirer.util;
|
|||||||
|
|
||||||
public class StringUtils
|
public class StringUtils
|
||||||
{
|
{
|
||||||
|
private static final String[] ILLEGAL_FILENAME_CHARACTERS = {"#", "%", "&", "{", "}", "\\", "<", ">",
|
||||||
|
"*", "?", "/", " ", "$", "!", "'", "\"", ":", "@", "+", "`", "|", "="};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares string a to b and returns true if a is non-null and non-empty, b is non-null and non-empty, and
|
* Compares string a to b and returns true if a is non-null and non-empty, b is non-null and non-empty, and
|
||||||
* a is equal to b.
|
* a is equal to b.
|
||||||
@@ -38,4 +41,15 @@ public class StringUtils
|
|||||||
{
|
{
|
||||||
return a == null || a.isEmpty();
|
return a == null || a.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces any illegal filename characters in the proposed filename
|
||||||
|
*/
|
||||||
|
public static String replaceIllegalCharacters(String filename) {
|
||||||
|
for (String illegalCharacter : ILLEGAL_FILENAME_CHARACTERS) {
|
||||||
|
filename = filename.replace(illegalCharacter, "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user