This repository has been archived by the owner on May 7, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[audio] Refactored use of filename, filename extension and separator (#…
…3837) * Refactored use of filename, filename extension and separator Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
- Loading branch information
Showing
7 changed files
with
144 additions
and
48 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
75 changes: 75 additions & 0 deletions
75
...ome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/utils/AudioStreamUtils.java
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,75 @@ | ||
/** | ||
* Copyright (c) 2014-2017 by the respective copyright holders. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.eclipse.smarthome.core.audio.utils; | ||
|
||
/** | ||
* Some general filename and extension utilities. | ||
* | ||
* @author Christoph Weitkamp - Initial contribution and API | ||
* | ||
*/ | ||
public class AudioStreamUtils { | ||
|
||
public static final String EXTENSION_SEPARATOR = "."; | ||
|
||
/** | ||
* Gets the base name of a filename. | ||
* | ||
* @param filename the filename to query | ||
* @return the base name of the file or an empty string if none exists or {@code null} if the filename is | ||
* {@code null} | ||
*/ | ||
public static String getBaseName(String filename) { | ||
if (filename == null) { | ||
return null; | ||
} | ||
final int index = filename.lastIndexOf(EXTENSION_SEPARATOR); | ||
if (index == -1) { | ||
return filename; | ||
} else { | ||
return filename.substring(0, index); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the extension of a filename. | ||
* | ||
* @param filename the filename to retrieve the extension of | ||
* @return the extension of the file or an empty string if none exists or {@code null} if the filename is | ||
* {@code null} | ||
*/ | ||
public static String getExtension(String filename) { | ||
if (filename == null) { | ||
return null; | ||
} | ||
final int index = filename.lastIndexOf(EXTENSION_SEPARATOR); | ||
if (index == -1) { | ||
return ""; | ||
} else { | ||
return filename.substring(index + 1); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the extension of a filename matches the given. | ||
* | ||
* @param filename the filename to check the extension of | ||
* @param extension the extension to check for | ||
* @return {@code true} if the filename has the specified extension | ||
*/ | ||
public static boolean isExtension(String filename, String extension) { | ||
if (filename == null) { | ||
return false; | ||
} | ||
if (extension == null || extension.isEmpty()) { | ||
return false; | ||
} | ||
return getExtension(filename).equals(extension); | ||
} | ||
|
||
} |
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