Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pushbullet] Refactor get content file name method #17982

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import static org.openhab.binding.pushbullet.internal.PushbulletBindingConstants.*;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
Expand Down Expand Up @@ -273,21 +271,10 @@ private boolean sendPush(PushRequest request) {
* Helper method to get the file name for a given content
*
* @param content the file content
* @return the file name if available, otherwise null
* @return the file name
*/
private @Nullable String getContentFileName(String content) {
if (content.startsWith("data:")) {
return IMAGE_FILE_NAME;
}
try {
Path fileName = Path.of(content.startsWith("http") ? new URL(content).getPath() : content).getFileName();
if (fileName != null) {
return fileName.toString();
}
} catch (MalformedURLException e) {
logger.debug("Malformed url content: {}", e.getMessage());
}
return null;
private String getContentFileName(String content) {
return content.startsWith("data:") ? IMAGE_FILE_NAME : Path.of(content).getFileName().toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems you removed URL support, is it because it's unused by the relevant Thing actions?

}

/**
Expand Down