Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 18 additions & 20 deletions java-desktop-util-demo/src/main/java/ec/util/demo/DesktopDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,34 @@
import ec.util.various.swing.BasicSwingLauncher;
import ec.util.various.swing.StandardSwingColor;
import ec.util.various.swing.TextPrompt;
import java.awt.Color;
import java.awt.Component;
import org.kordamp.ikonli.materialdesign.MaterialDesign;
import org.kordamp.ikonli.swing.FontIcon;

import javax.swing.*;
import javax.swing.border.Border;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.kordamp.ikonli.materialdesign.MaterialDesign;
import org.kordamp.ikonli.swing.FontIcon;

/**
*
Expand Down Expand Up @@ -93,7 +89,8 @@ public DesktopDemo() {
jList1.setCellRenderer(new KnownFolderRenderer());

try {
sample = File.createTempFile("test", ".txt");
Path tempFile = Files.createTempFile("test", ".txt");
sample = tempFile.toFile();
sample.deleteOnExit();
} catch (IOException ex) {
reportException(ex);
Expand Down Expand Up @@ -407,7 +404,8 @@ private void showInFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {

private void moveToTrashButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveToTrashButtonActionPerformed
try {
desktop.moveToTrash(File.createTempFile("test", ".txt"));
Path tempFile = Files.createTempFile("test", ".txt");
desktop.moveToTrash(tempFile.toFile());
} catch (IOException ex) {
reportException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import java.awt.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;

import static java.net.HttpURLConnection.HTTP_OK;

Expand Down Expand Up @@ -40,8 +39,8 @@ public Image getFaviconOrNull(@NonNull FaviconRef ref, @NonNull URLConnectionFac
return NO_FAVICON;
}

private static URL getFaviconRequest(FaviconRef ref) throws MalformedURLException {
return new URL("https://api.faviconkit.com/" + ref.getDomain() + "/" + ref.getSize());
private static URI getFaviconRequest(FaviconRef ref) {
return URI.create("https://api.faviconkit.com/" + ref.getDomain() + "/" + ref.getSize());
}

private static boolean isDefaultFavicon(@Nullable String contentType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import java.awt.*;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;

import static java.net.HttpURLConnection.HTTP_OK;

Expand All @@ -37,9 +36,9 @@ public Image getFaviconOrNull(@NonNull FaviconRef ref, @NonNull URLConnectionFac
}
}

private URL getFaviconRequest(FaviconRef ref) throws MalformedURLException {
private URI getFaviconRequest(FaviconRef ref) {
int roundedSize = roundSize(ref.getSize());
return new URL("https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://" + ref.getDomain() + "&size=" + roundedSize);
return URI.create("https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://" + ref.getDomain() + "&size=" + roundedSize);
}

private static boolean isDefaultFavicon(int responseCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;

import static java.net.HttpURLConnection.HTTP_OK;

Expand Down Expand Up @@ -41,8 +40,8 @@ public Image getFaviconOrNull(@NonNull FaviconRef ref, @NonNull URLConnectionFac
return NO_FAVICON;
}

private static URL getFaviconRequest(FaviconRef ref) throws MalformedURLException {
return new URL("https://icon.horse/icon/" + ref.getDomain());
private static URI getFaviconRequest(FaviconRef ref) {
return URI.create("https://icon.horse/icon/" + ref.getDomain());
}

private static boolean isDefaultFavicon(@Nullable String contentType, @Nullable BufferedImage image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URI;
import java.net.URLConnection;

@lombok.RequiredArgsConstructor(access = AccessLevel.PRIVATE)
final class ImageConnection implements Closeable {

public static @NonNull ImageConnection open(@NonNull URLConnectionFactory factory, @NonNull URL url) throws IOException {
URLConnection connection = factory.openConnection(url);
public static @NonNull ImageConnection open(@NonNull URLConnectionFactory factory, @NonNull URI uri) throws IOException {
URLConnection connection = factory.openConnection(uri.toURL());
if (!(connection instanceof HttpURLConnection)) {
throw new IOException("Invalid url " + url);
throw new IOException("Invalid url " + uri);
}
connection.connect();
return new ImageConnection((HttpURLConnection) connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.jupiter.api.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;

import static org.assertj.core.api.Assertions.*;

Expand All @@ -13,7 +13,7 @@ public class DomainNameTest {
public void testOf() throws MalformedURLException {
assertThatNullPointerException().isThrownBy(() -> DomainName.of(null));

assertThat(DomainName.of(new URL("https://www.google.com")))
assertThat(DomainName.of(URI.create("https://www.google.com").toURL()))
.hasToString("www.google.com");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.*;
import java.util.*;
import java.util.function.Function;

Expand Down Expand Up @@ -82,11 +79,12 @@ public static File checkFileValidation(@NonNull File file) throws NullPointerExc

@NonNull
public static File extractResource(@NonNull String resourceName, @NonNull String filePrefix, @NonNull String fileSuffix) throws IOException {
File result = File.createTempFile(filePrefix, fileSuffix);
result.deleteOnExit();
Path tempFile = Files.createTempFile(filePrefix, fileSuffix);
try (InputStream in = AwtDesktop.class.getResourceAsStream(resourceName)) {
Files.copy(in, result.toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(Objects.requireNonNull(in), tempFile, StandardCopyOption.REPLACE_EXISTING);
}
File result = tempFile.toFile();
result.deleteOnExit();
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
*/
package ec.util.desktop.impl;

import lombok.NonNull;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Collections;
import java.util.Locale;
import lombok.NonNull;

/**
* Facade that allows executing script in Windows Script Host.
Expand Down Expand Up @@ -162,10 +164,11 @@ public boolean canExec(@NonNull String script, @NonNull String language) {

@Override
public @NonNull Process exec(@NonNull String script, @NonNull String language, String... args) throws IOException {
File file = File.createTempFile("script", Language.getByName(language).getExtension());
file.deleteOnExit();
Files.write(file.toPath(), Collections.singleton(script), StandardCharsets.UTF_8, StandardOpenOption.APPEND);
return exec(file, args);
Path tempFile = Files.createTempFile("script", Language.getByName(language).getExtension());
Files.write(tempFile, Collections.singleton(script), StandardCharsets.UTF_8, StandardOpenOption.APPEND);
File result = tempFile.toFile();
result.deleteOnExit();
return exec(result, args);
}

private enum Language {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

Expand All @@ -54,7 +56,8 @@ public class WinDesktopTest {
public static void beforeClass() throws IOException {
assumeThat(java.awt.Desktop.isDesktopSupported()).isTrue();

File script = File.createTempFile("search", "");
Path tempFile = Files.createTempFile("search", "");
File script = tempFile.toFile();
script.deleteOnExit();
GOOD = new Input(FakeRegistry.create(), script, new FakeLauncher(), new FakeSearch());
BAD = new Input(WinRegistry.noOp(), Paths.get("helloworld").toFile(), ZSystem.noOp(), WinSearch.noOp());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
Expand Down
Loading