-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
56 additions
and
28 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
Binary file not shown.
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
19 changes: 19 additions & 0 deletions
19
jcommons/src/main/java/org/mbari/jcommons/util/AutoCloseableLock.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,19 @@ | ||
package org.mbari.jcommons.util; | ||
|
||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
|
||
public class AutoCloseableLock extends ReentrantLock implements AutoCloseable { | ||
|
||
public AutoCloseableLock lockAndGet() { | ||
lock(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
unlock(); | ||
} | ||
|
||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
scommons/src/main/scala/org/mbari/scommons/etc/jdk/Uris.scala
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 |
---|---|---|
@@ -1,7 +1,25 @@ | ||
package org.mbari.scommons.etc.jdk | ||
|
||
import java.net.URI | ||
import Loggers.given | ||
import scala.util.control.NonFatal | ||
import java.net.HttpURLConnection | ||
|
||
object Uris: | ||
|
||
private val log = System.getLogger(getClass.getName) | ||
|
||
def filename(uri: URI): String = uri.getPath.split('/').last | ||
|
||
def exists(uri: URI): Boolean = try | ||
HttpURLConnection.setFollowRedirects(false) | ||
val connection = uri.toURL.openConnection().asInstanceOf[HttpURLConnection] | ||
connection.setRequestMethod("HEAD") | ||
connection.getResponseCode == HttpURLConnection.HTTP_OK | ||
catch | ||
case NonFatal(e) => | ||
log | ||
.atWarn | ||
.withCause(e) | ||
.log(s"Failed to connect to $uri") | ||
false |
2 changes: 1 addition & 1 deletion
2
scommons/src/main/scala/org/mbari/scommons/math/FastCollator.scala
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