Skip to content
This repository was archived by the owner on May 7, 2020. It is now read-only.

[audio] Refactored use of filename, filename extension and separator #3837

Merged
merged 5 commits into from
Jul 24, 2017
Merged

[audio] Refactored use of filename, filename extension and separator #3837

merged 5 commits into from
Jul 24, 2017

Conversation

cweitkamp
Copy link
Contributor

@cweitkamp cweitkamp commented Jul 13, 2017

  • Refactored use of filename, filename extension and separator
  • Added util class for handling filenames and filename extensions
  • Applied changes to Sonos binding

Signed-off-by: Christoph Weitkamp [email protected]

@cweitkamp
Copy link
Contributor Author

cweitkamp commented Jul 13, 2017

Pointing to this discussion.

I think we schould discuss the naming of the util class and wether we consider to move the declarations of the *_EXTENSION contants into the util class or not.

Copy link
Contributor

@htreu htreu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for this nice refactoring & improvement. I left some remarks inline.

@@ -0,0 +1,75 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats is the reason for this class? We have org.apache.commons.io already in the classpath which provides FilenameUtils. The methods are identical to these implemented here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htreu thanks for your review. Have a look at this discussion. I suggested to use that util class, but we decided to be less dependant. That is the reason for my own implementation.

case M3U_EXTENSION:
InputStream isM3U = new URL(url).openStream();
String urlsM3U = IOUtils.toString(isM3U);
for (String line : urlsM3U.split("\n")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 65 & 66 might also be a call to IOUtils.readLines(is) which does provide a List<String> ready to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. The use of IOUtils.toString(InputStream input) is deprecated since org.apache.commons.io v2.5, so we should adopt that anyway.

case PLS_EXTENSION:
InputStream isPLS = new URL(url).openStream();
String urlsPLS = IOUtils.toString(isPLS);
for (String line : urlsPLS.split("\n")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here to read lines by IOUtils.readLines(is).

@cweitkamp
Copy link
Contributor Author

@htreu I applied the changes.

final String extension = AudioStreamUtils.getExtension(filename);
switch (extension) {
case M3U_EXTENSION:
final InputStream isM3U = new URL(url).openStream();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about closing the stream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I changed it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java.io.InputStream implements Closeable and so AutoCloseable.
Why not using try-with-resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This design pattern is new to me, thanks for pointing to it. It looks like the best solution for this.

}
break;
case PLS_EXTENSION:
final InputStream isPLS = new URL(url).openStream();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about closing the stream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I changed it. Maybe the try {} catch {} block is placed incorrect now and should be refactored / split up as well.

Signed-off-by: Christoph Weitkamp <[email protected]>
Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp
Copy link
Contributor Author

@maggu2810 thanks for review, I refactored the code to use the try-with-resources statement.

Copy link
Contributor

@maggu2810 maggu2810 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks.

Just one minor remark about non-necessary braces.

@SJKA have all your requested changes been implemented?

if (filename == null) {
return false;
}
if ((extension == null) || extension.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove the braces around the first check.

Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp
Copy link
Contributor Author

@maggu2810 done. If you want me to squash my commits, please let me know.

@maggu2810 maggu2810 merged commit bea7bd7 into eclipse-archived:master Jul 24, 2017
@maggu2810
Copy link
Contributor

If you want me to squash my commits, please let me know.

We can do it on merging.

Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants