Skip to content
Open
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
Binary file not shown.
Binary file added bin/main/algorithm/BinarySearchSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/BubbleSortSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/CountingSortSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/CycleSortSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/DammSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/InsertionSortSnippet.class
Binary file not shown.
Binary file not shown.
Binary file added bin/main/algorithm/LinearSearchSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/LuhnModnSnippet.class
Binary file not shown.
Binary file modified bin/main/algorithm/MergeSortSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/QuickSortSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/SelectionSortSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/SieveOfEratosthenesSnippet.class
Binary file not shown.
Binary file added bin/main/algorithm/VerhoeffSnippet.class
Binary file not shown.
Binary file added bin/main/array/AllEqualSnippet.class
Binary file not shown.
Binary file added bin/main/array/ArrayConcatSnippet.class
Binary file not shown.
Binary file added bin/main/array/ArrayMeanSnippet.class
Binary file not shown.
Binary file added bin/main/array/ArrayMedianSnippet.class
Binary file not shown.
Binary file added bin/main/array/ArrayModeInPlaceSnippet.class
Binary file not shown.
Binary file added bin/main/array/ArrayModeSnippet.class
Binary file not shown.
Binary file added bin/main/array/ArraySumSnippet.class
Binary file not shown.
Binary file added bin/main/array/FindMaxSnippet.class
Binary file not shown.
Binary file modified bin/main/array/FindMinSnippet.class
Binary file not shown.
Binary file not shown.
Binary file added bin/main/array/ReverseArraySnippet.class
Binary file not shown.
Binary file added bin/main/cls/CreatingObjectSnippet.class
Binary file not shown.
Binary file added bin/main/cls/GetAllFieldNamesSnippet.class
Binary file not shown.
Binary file added bin/main/cls/GetAllMethodsSnippet.class
Binary file not shown.
Binary file added bin/main/cls/GetAllPublicFieldNamesSnippet.class
Binary file not shown.
Binary file added bin/main/date/AddDaysToDateSnippet.class
Binary file not shown.
Binary file added bin/main/date/DateDifferenceSnippet.class
Binary file not shown.
Binary file added bin/main/encoding/Base64DecodeSnippet.class
Binary file not shown.
Binary file added bin/main/encoding/Base64EncodeSnippet.class
Binary file not shown.
Binary file added bin/main/file/ListAllFilesSnippet.class
Binary file not shown.
Binary file added bin/main/file/ListDirectoriesSnippet.class
Binary file not shown.
Binary file added bin/main/file/ListFilesInDirectorySnippet.class
Binary file not shown.
Binary file added bin/main/file/ReadLinesSnippet.class
Binary file not shown.
Binary file added bin/main/file/ZipDirectorySnippet.class
Binary file not shown.
Binary file added bin/main/file/ZipFileSnippet.class
Binary file not shown.
Binary file added bin/main/file/ZipFilesSnippet.class
Binary file not shown.
Binary file added bin/main/io/InputStreamToStringSnippet.class
Binary file not shown.
Binary file added bin/main/io/ReadFileSnippet.class
Binary file not shown.
Binary file added bin/main/math/DiceThrow$DiceSides.class
Binary file not shown.
Binary file added bin/main/math/DiceThrow.class
Binary file not shown.
Binary file added bin/main/math/EloRatingSnippet.class
Binary file not shown.
Binary file added bin/main/math/EvenOdd.class
Binary file not shown.
Binary file added bin/main/math/FactorialSnippet.class
Binary file not shown.
Binary file added bin/main/math/FibonacciSnippet.class
Binary file not shown.
Binary file added bin/main/math/GreatestCommonDivisorSnippet.class
Binary file not shown.
Binary file added bin/main/math/HaversineFormulaSnippet.class
Binary file not shown.
Binary file added bin/main/math/LeastCommonMultipleSnippet.class
Binary file not shown.
Binary file added bin/main/math/LuhnSnippet.class
Binary file not shown.
Binary file not shown.
Binary file added bin/main/math/PerformLotterySnippet.class
Binary file not shown.
Binary file added bin/main/math/PrimeNumberSnippet.class
Binary file not shown.
Binary file added bin/main/math/RandomNumber.class
Binary file not shown.
Binary file added bin/main/math/SquareRoot.class
Binary file not shown.
Binary file added bin/main/media/CaptureScreenSnippet.class
Binary file not shown.
Binary file added bin/main/media/PlaySoundSnippet.class
Binary file not shown.
Binary file added bin/main/network/HttpGetSnippet.class
Binary file not shown.
Binary file added bin/main/network/HttpPostSnippet.class
Binary file not shown.
Binary file added bin/main/string/AnagramSnippet.class
Binary file not shown.
Binary file added bin/main/string/CommonLettersSnippet.class
Binary file not shown.
Binary file added bin/main/string/CompareVersionSnippet.class
Binary file not shown.
Binary file added bin/main/string/DuplicateCharacterSnippet.class
Binary file not shown.
Binary file added bin/main/string/FormatBytesSnippet.class
Binary file not shown.
Binary file added bin/main/string/KmpSubstringSearchSnippet.class
Binary file not shown.
Binary file not shown.
Binary file added bin/main/string/LindenmayerSystemSnippet.class
Binary file not shown.
Binary file added bin/main/string/MaxCharacterCountSnippet.class
Binary file not shown.
Binary file added bin/main/string/PalindromCheckSnippet.class
Binary file not shown.
Binary file added bin/main/string/ReverseStringSnippet.class
Binary file not shown.
Binary file added bin/main/string/StringToDateSnippet.class
Binary file not shown.
Binary file added bin/main/thread/ThreadPool.class
Binary file not shown.
Binary file added bin/main/thread/ThreadSnippet.class
Binary file not shown.
Binary file not shown.
Binary file added bin/test/algorithm/BinarySearchSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/BubbleSortSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/CountingSortSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/CycleSortSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/DammSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/InsertionSortSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file added bin/test/algorithm/LinearSearchSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/LuhnModnSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/MergeSortSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/QuickSortSnippetTest.class
Binary file not shown.
Binary file added bin/test/algorithm/SelectionSortSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file added bin/test/algorithm/VerhoeffSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/AllEqualSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/ArrayConcatSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/ArrayMeanSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/ArrayMedianSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/ArrayModeInPlaceSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/ArrayModeSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/ArraySumSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/FindMaxSnippetTest.class
Binary file not shown.
Binary file added bin/test/array/FindMinSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file added bin/test/array/ReverseArrayTest.class
Binary file not shown.
Binary file added bin/test/cls/CreatingObjectSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/test/cls/GetAllFieldNamesSnippetTest.class
Binary file not shown.
Binary file added bin/test/cls/GetAllMethodsSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/test/date/AddDaysToDateSnippetTest.class
Binary file not shown.
Binary file added bin/test/date/DateDifferenceSnippetTest.class
Binary file not shown.
7 changes: 7 additions & 0 deletions bin/test/dir1/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ąćśź
←≠²³¢²€
июля
åøä
ñí
7月15日起
خەيرلىك ئەتىگەن!
Empty file added bin/test/dir2/placeholder.txt
Empty file.
Empty file.
Empty file added bin/test/dir3/innerfile.txt
Empty file.
Binary file added bin/test/encoding/Base64DecodeSnippetTest.class
Binary file not shown.
Binary file added bin/test/encoding/Base64EncodeSnippetTest.class
Binary file not shown.
Binary file added bin/test/file/ListAllFilesSnippetTest.class
Binary file not shown.
Binary file added bin/test/file/ListDirectoriesSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file added bin/test/file/ReadLinesSnippetTest.class
Binary file not shown.
Binary file added bin/test/file/ZipDirectorySnippetTest.class
Binary file not shown.
Binary file added bin/test/file/ZipFileSnippetTest.class
Binary file not shown.
Binary file added bin/test/file/ZipFilesSnippetTest.class
Binary file not shown.
Binary file added bin/test/io/InputStreamToStringSnippetTest.class
Binary file not shown.
Binary file added bin/test/io/ReadFileSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/DiceThrowTest.class
Binary file not shown.
Binary file added bin/test/math/EloRatingSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/EvenOddTest.class
Binary file not shown.
Binary file added bin/test/math/FactorialSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/FibonacciSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/GreatestCommonDivisorSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/HaversineFormulaSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/LeastCommonMultipleSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/LuhnSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file added bin/test/math/PerformLotterySnippetTest.class
Binary file not shown.
Binary file added bin/test/math/PrimeNumberSnippetTest.class
Binary file not shown.
Binary file added bin/test/math/RandomNumberTest.class
Binary file not shown.
Binary file added bin/test/math/SquareRootTest.class
Binary file not shown.
Binary file added bin/test/media/CaptureScreenSnippetTest.class
Binary file not shown.
Binary file added bin/test/network/HttpGetSnippetTest.class
Binary file not shown.
Binary file added bin/test/network/HttpPostSnippetTest.class
Binary file not shown.
3 changes: 3 additions & 0 deletions bin/test/somelines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo
bar
baz
2 changes: 2 additions & 0 deletions bin/test/someotherlines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
123
XYZ
Binary file added bin/test/string/AnagramSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/CommonLettersSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/CompareVersionSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/DuplicateCharacterSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/FormatBytesSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/KmpSubstringSearchSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/LevenshteinDistanceSnippetTest.class
Binary file not shown.
Binary file not shown.
Binary file added bin/test/string/MaxCharacterCountSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/PalindromCheckSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/ReverseStringSnippetTest.class
Binary file not shown.
Binary file added bin/test/string/StringToDateSnippetTest.class
Binary file not shown.
Binary file added bin/test/thread/ThreadPoolTest.class
Binary file not shown.
Binary file added bin/test/thread/ThreadSnippetTest.class
Binary file not shown.
84 changes: 84 additions & 0 deletions src/main/java/media/PlaySoundSnippet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* MIT License
*
* Copyright (c) 2017-2022 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package media;

import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

/**
* PlaySoundSnippet.
*
* <p>Plays a sound file using the Java Sound API. No external libraries are used. This method
* blocks until playback completes. Common supported formats are WAV, AIFF and AU; actual
* supported formats depend on the runtime JVM/platform.
*/
public class PlaySoundSnippet {

/**
* Play a sound file and block until playback finishes.
*
* @param filename path to the audio file
* @throws IOException if an I/O error occurs
* @throws UnsupportedAudioFileException if the audio file format is not supported
* @throws LineUnavailableException if a clip line cannot be opened
* @throws InterruptedException if the thread is interrupted while waiting for playback
*/
public static void playSound(String filename)
throws IOException, UnsupportedAudioFileException, LineUnavailableException, InterruptedException {
var file = new File(filename);
try (AudioInputStream audioIn = AudioSystem.getAudioInputStream(file)) {
Clip clip = AudioSystem.getClip();
clip.open(audioIn);

final Object lock = new Object();
final boolean[] finished = {false};

clip.addLineListener((LineEvent event) -> {
if (event.getType() == LineEvent.Type.STOP) {
synchronized (lock) {
finished[0] = true;
lock.notifyAll();
}
}
});

clip.start();

synchronized (lock) {
while (!finished[0]) {
lock.wait();
}
}

clip.close();
}
}
}
Loading