Compare commits
5 Commits
a51bd5e574
...
d28485c0c8
| Author | SHA1 | Date | |
|---|---|---|---|
| d28485c0c8 | |||
| dfde55f05d | |||
| 46c07638a7 | |||
| 2832fa0b5f | |||
| 1a6ee1f972 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@
|
|||||||
/build/
|
/build/
|
||||||
/**/build/**
|
/**/build/**
|
||||||
/test.db
|
/test.db
|
||||||
|
/out/
|
||||||
|
|||||||
16
batik/build.gradle.kts
Normal file
16
batik/build.gradle.kts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-rasterizer
|
||||||
|
implementation("org.apache.xmlgraphics:batik-rasterizer:1.14")
|
||||||
|
|
||||||
|
}
|
||||||
51
batik/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
51
batik/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import org.apache.batik.transcoder.TranscoderException;
|
||||||
|
import org.apache.batik.transcoder.TranscoderInput;
|
||||||
|
import org.apache.batik.transcoder.TranscoderOutput;
|
||||||
|
import org.apache.batik.transcoder.image.PNGTranscoder;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class Sample {
|
||||||
|
public static void main(String... args) throws IOException, TranscoderException {
|
||||||
|
toBufferedImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toPNG() throws FileNotFoundException, TranscoderException {
|
||||||
|
PNGTranscoder transcoder = new PNGTranscoder();
|
||||||
|
transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, 64f);
|
||||||
|
transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, 64f);
|
||||||
|
|
||||||
|
TranscoderInput input = new TranscoderInput(Sample.class
|
||||||
|
.getResourceAsStream("/java.svg"));
|
||||||
|
TranscoderOutput output = new TranscoderOutput(
|
||||||
|
new FileOutputStream(new File("out/test_out.png")));
|
||||||
|
transcoder.transcode(input, output);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toBufferedImage() throws IOException, TranscoderException {
|
||||||
|
PNGTranscoder transcoder = new PNGTranscoder();
|
||||||
|
transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, 64f);
|
||||||
|
transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, 64f);
|
||||||
|
|
||||||
|
TranscoderInput input = new TranscoderInput(Sample.class
|
||||||
|
.getResourceAsStream("/java.svg"));
|
||||||
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
TranscoderOutput output = new TranscoderOutput(os);
|
||||||
|
transcoder.transcode(input, output);
|
||||||
|
|
||||||
|
BufferedImage out = ImageIO.read(new ByteArrayInputStream(os.toByteArray()));
|
||||||
|
ImageIO.write(out, "png", new File("out/test-buffered-image.png"));
|
||||||
|
}
|
||||||
|
}
|
||||||
1
batik/src/main/resources/java.svg
Normal file
1
batik/src/main/resources/java.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="2500" height="2500" viewBox="0 0 192.756 192.756"><g fill-rule="evenodd" clip-rule="evenodd"><path fill="#fff" d="M0 0h192.756v192.756H0V0z"/><path d="M80.372 101.729s-4.604 2.679 3.28 3.584c9.554 1.091 14.434.934 24.959-1.057 0 0 2.771 1.735 6.639 3.236-23.601 10.113-53.413-.585-34.878-5.763zM77.487 88.532s-5.165 3.823 2.726 4.639c10.206 1.054 18.262 1.14 32.211-1.544 0 0 1.926 1.955 4.957 3.023-28.531 8.345-60.307.657-39.894-6.118z" fill="#3174b9"/><path d="M101.797 66.143c5.818 6.697-1.525 12.72-1.525 12.72s14.766-7.621 7.984-17.168c-6.332-8.899-11.189-13.32 15.102-28.566-.001-.001-41.27 10.303-21.561 33.014z" fill="#ca3132"/><path d="M133.01 111.491s3.408 2.81-3.754 4.983c-13.619 4.125-56.694 5.369-68.659.164-4.298-1.872 3.766-4.467 6.303-5.015 2.646-.572 4.156-.468 4.156-.468-4.783-3.368-30.916 6.615-13.272 9.479 48.112 7.801 87.704-3.512 75.226-9.143zM82.587 74.857s-21.908 5.205-7.757 7.097c5.977.799 17.883.615 28.982-.316 9.068-.761 18.17-2.389 18.17-2.389s-3.195 1.371-5.51 2.949c-22.251 5.853-65.229 3.127-52.855-2.856 10.462-5.061 18.97-4.485 18.97-4.485zM121.891 96.824c22.617-11.75 12.16-23.044 4.859-21.522-1.785.373-2.586.695-2.586.695s.666-1.042 1.932-1.49c14.441-5.075 25.545 14.972-4.656 22.911-.001 0 .347-.314.451-.594z" fill="#3174b9"/><path d="M108.256 8.504s12.523 12.531-11.881 31.794c-19.571 15.458-4.462 24.269-.006 34.34-11.426-10.307-19.807-19.382-14.185-27.826 8.254-12.395 31.125-18.406 26.072-38.308z" fill="#ca3132"/><path d="M84.812 128.674c21.706 1.388 55.045-.771 55.836-11.044 0 0-1.518 3.894-17.941 6.983-18.529 3.488-41.386 3.082-54.938.845 0 0 2.777 2.298 17.043 3.216z" fill="#3174b9"/><path d="M139.645 147.096h-.66v-.37h1.781v.37h-.66v1.848h-.461v-1.848zm3.554.092h-.008l-.656 1.755h-.301l-.652-1.755h-.008v1.755h-.438v-2.218h.643l.604 1.569.604-1.569h.637v2.218h-.424v-1.755h-.001zM81.255 167.921c-2.047 1.774-4.211 2.772-6.154 2.772-2.768 0-4.27-1.663-4.27-4.324 0-2.881 1.608-4.989 8.044-4.989h2.379v6.541h.001zm5.65 6.374v-19.732c0-5.043-2.876-8.371-9.809-8.371-4.045 0-7.591.999-10.474 2.272l.83 3.495c2.271-.834 5.207-1.607 8.089-1.607 3.994 0 5.713 1.607 5.713 4.934v2.495h-1.996c-9.702 0-14.08 3.764-14.08 9.423 0 4.876 2.885 7.648 8.316 7.648 3.491 0 6.099-1.441 8.534-3.55l.443 2.993h4.434zM105.762 174.295h-7.045l-8.483-27.601h6.154l5.265 16.961 1.172 5.096c2.656-7.371 4.541-14.854 5.484-22.057h5.984c-1.602 9.088-4.488 19.066-8.531 27.601zM132.799 167.921c-2.053 1.774-4.217 2.772-6.156 2.772-2.768 0-4.268-1.663-4.268-4.324 0-2.881 1.609-4.989 8.041-4.989h2.383v6.541zm5.652 6.374v-19.732c0-5.043-2.885-8.371-9.811-8.371-4.049 0-7.594.999-10.477 2.272l.83 3.495c2.271-.834 5.213-1.607 8.096-1.607 3.988 0 5.709 1.607 5.709 4.934v2.495h-1.996c-9.703 0-14.078 3.764-14.078 9.423 0 4.876 2.879 7.648 8.311 7.648 3.494 0 6.098-1.441 8.539-3.55l.445 2.993h4.432zM58.983 178.985c-1.61 2.353-4.214 4.216-7.061 5.267l-2.79-3.286c2.169-1.113 4.027-2.91 4.892-4.582.745-1.49 1.056-3.406 1.056-7.992v-31.515h6.005v31.08c0 6.134-.49 8.613-2.102 11.028z" fill="#ca3132"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples.new_http;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.WebSocket;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.CompletionStage;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class WebSocketSample {
|
||||||
|
private static class WebSocketListener implements WebSocket.Listener {
|
||||||
|
private StringBuilder sb;
|
||||||
|
|
||||||
|
WebSocketListener() {
|
||||||
|
sb = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(WebSocket webSocket) {
|
||||||
|
log.debug("Open!");
|
||||||
|
//webSocket.request(1);
|
||||||
|
WebSocket.Listener.super.onOpen(webSocket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last) {
|
||||||
|
sb.append(data);
|
||||||
|
webSocket.request(1);
|
||||||
|
|
||||||
|
if (last) {
|
||||||
|
String message = sb.toString();
|
||||||
|
|
||||||
|
log.debug("Rx: {}", message);
|
||||||
|
|
||||||
|
sb = new StringBuilder();
|
||||||
|
|
||||||
|
return CompletableFuture.completedStage(null);
|
||||||
|
}
|
||||||
|
//return WebSocket.Listener.super.onText(webSocket, data, last);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(WebSocket webSocket, Throwable error) {
|
||||||
|
log.error("Error!", error);
|
||||||
|
WebSocket.Listener.super.onError(webSocket, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) throws ExecutionException, InterruptedException {
|
||||||
|
HttpClient httpClient = HttpClient.newHttpClient();
|
||||||
|
CompletableFuture<WebSocket> completableFuture = httpClient.newWebSocketBuilder()
|
||||||
|
.buildAsync(URI.create("ws://localhost:8080/websocket"), new WebSocketListener());
|
||||||
|
|
||||||
|
WebSocket webSocket = completableFuture.get();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
Thread.sleep(1500);
|
||||||
|
webSocket.sendText("Hello", false);
|
||||||
|
webSocket.sendText(" World", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
14
serial-io/build.gradle.kts
Normal file
14
serial-io/build.gradle.kts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("com.fazecast:jSerialComm:2.7.0")
|
||||||
|
}
|
||||||
35
serial-io/src/main/java/kr/pe/elex/examples/Blocking.java
Normal file
35
serial-io/src/main/java/kr/pe/elex/examples/Blocking.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import com.fazecast.jSerialComm.SerialPort;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Blocking {
|
||||||
|
public static void main(String... args) {
|
||||||
|
SerialPort serialPort = SerialPort.getCommPort("/dev/ttyS0");
|
||||||
|
serialPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY);
|
||||||
|
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, 1000, 0);
|
||||||
|
serialPort.openPort();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
byte[] buffer = new byte[512];
|
||||||
|
int numRead = serialPort.readBytes(buffer, buffer.length);
|
||||||
|
Console.writeLine(buffer);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Oops!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
serialPort.closePort();
|
||||||
|
}
|
||||||
|
}
|
||||||
127
serial-io/src/main/java/kr/pe/elex/examples/ListeningEvents.java
Normal file
127
serial-io/src/main/java/kr/pe/elex/examples/ListeningEvents.java
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import com.fazecast.jSerialComm.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class ListeningEvents {
|
||||||
|
public static void main(String... args) {
|
||||||
|
SerialPort serialPort = SerialPort.getCommPort("/dev/ttyS0");
|
||||||
|
serialPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY);
|
||||||
|
serialPort.openPort();
|
||||||
|
|
||||||
|
serialPort.addDataListener(new SerialPortDataListener() {
|
||||||
|
@Override
|
||||||
|
public int getListeningEvents() {
|
||||||
|
return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialEvent(SerialPortEvent event) {
|
||||||
|
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
|
||||||
|
return;
|
||||||
|
byte[] newData = new byte[serialPort.bytesAvailable()];
|
||||||
|
int numRead = serialPort.readBytes(newData, newData.length);
|
||||||
|
Console.writeLine(newData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serialPort.addDataListener(new SerialPortDataListener() {
|
||||||
|
@Override
|
||||||
|
public int getListeningEvents() {
|
||||||
|
return SerialPort.LISTENING_EVENT_DATA_WRITTEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialEvent(SerialPortEvent event) {
|
||||||
|
if (event.getEventType() == SerialPort.LISTENING_EVENT_DATA_WRITTEN)
|
||||||
|
Console.writeLine("All bytes were successfully transmitted!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serialPort.addDataListener(new SerialPortDataListener() {
|
||||||
|
@Override
|
||||||
|
public int getListeningEvents() {
|
||||||
|
return SerialPort.LISTENING_EVENT_DATA_RECEIVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialEvent(SerialPortEvent event) {
|
||||||
|
byte[] newData = event.getReceivedData();
|
||||||
|
Console.writeLine(newData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serialPort.addDataListener(new SerialPortPacketListener(){
|
||||||
|
@Override
|
||||||
|
public int getListeningEvents() {
|
||||||
|
return SerialPort.LISTENING_EVENT_DATA_RECEIVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialEvent(SerialPortEvent event) {
|
||||||
|
byte[] newData = event.getReceivedData();
|
||||||
|
Console.writeLine(newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPacketSize() {
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serialPort.addDataListener(new SerialPortMessageListener(){
|
||||||
|
@Override
|
||||||
|
public int getListeningEvents() {
|
||||||
|
return SerialPort.LISTENING_EVENT_DATA_RECEIVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialEvent(SerialPortEvent event) {
|
||||||
|
byte[] newData = event.getReceivedData();
|
||||||
|
Console.writeLine(newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getMessageDelimiter() {
|
||||||
|
return new byte[]{0x7e};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delimiterIndicatesEndOfMessage() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serialPort.addDataListener(new SerialPortMessageListener(){
|
||||||
|
@Override
|
||||||
|
public int getListeningEvents() {
|
||||||
|
return SerialPort.LISTENING_EVENT_DATA_RECEIVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialEvent(SerialPortEvent event) {
|
||||||
|
byte[] newData = event.getReceivedData();
|
||||||
|
Console.writeLine(newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getMessageDelimiter() {
|
||||||
|
return new byte[]{'\n'};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delimiterIndicatesEndOfMessage() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
38
serial-io/src/main/java/kr/pe/elex/examples/NonBlocking.java
Normal file
38
serial-io/src/main/java/kr/pe/elex/examples/NonBlocking.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import com.fazecast.jSerialComm.SerialPort;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class NonBlocking {
|
||||||
|
public static void main(String... args) {
|
||||||
|
SerialPort serialPort = SerialPort.getCommPort("/dev/ttyS0");
|
||||||
|
serialPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY);
|
||||||
|
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_NONBLOCKING, 0, 0);
|
||||||
|
serialPort.openPort();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
while (serialPort.bytesAvailable() == 0) {
|
||||||
|
Thread.sleep(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] buffer = new byte[serialPort.bytesAvailable()];
|
||||||
|
int numRead = serialPort.readBytes(buffer, buffer.length);
|
||||||
|
Console.writeLine(buffer);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Oops!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
serialPort.closePort();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
serial-io/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
11
serial-io/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
public class Sample {
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import com.fazecast.jSerialComm.SerialPort;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class SemiBlocking {
|
||||||
|
public static void main(String... args) {
|
||||||
|
SerialPort serialPort = SerialPort.getCommPort("/dev/ttyS0");
|
||||||
|
serialPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY);
|
||||||
|
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 100, 0);
|
||||||
|
serialPort.openPort();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
byte[] buffer = new byte[512];
|
||||||
|
int numRead = serialPort.readBytes(buffer, buffer.length);
|
||||||
|
Console.writeLine(buffer);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Oops!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
serialPort.closePort();
|
||||||
|
}
|
||||||
|
}
|
||||||
46
serial-io/src/main/java/kr/pe/elex/examples/Streaming.java
Normal file
46
serial-io/src/main/java/kr/pe/elex/examples/Streaming.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import com.fazecast.jSerialComm.SerialPort;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Streaming {
|
||||||
|
public static void main(String... args) {
|
||||||
|
SerialPort serialPort = SerialPort.getCommPort("/dev/ttyS0");
|
||||||
|
serialPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY);
|
||||||
|
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
|
||||||
|
serialPort.openPort();
|
||||||
|
|
||||||
|
BufferedInputStream is = new BufferedInputStream(serialPort.getInputStream());
|
||||||
|
BufferedOutputStream os = new BufferedOutputStream(serialPort.getOutputStream());
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
if (is.available()<=0){
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] buffer = new byte[is.available()];
|
||||||
|
int numRead = is.read(buffer);
|
||||||
|
Console.writeLine(buffer);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Oops!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
serialPort.closePort();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,11 +9,11 @@ rootProject.name = "java-examples"
|
|||||||
include(
|
include(
|
||||||
"json-web-token", "mockito",
|
"json-web-token", "mockito",
|
||||||
"mosquitto", "rabbit-mq",
|
"mosquitto", "rabbit-mq",
|
||||||
"ssh",
|
"ssh", "batik", "webcam",
|
||||||
"web-socket-servlet", "web-socket-client",
|
"web-socket-servlet", "web-socket-client",
|
||||||
"thread", "hibernate", "jdbc-sqlite",
|
"thread", "hibernate", "jdbc-sqlite",
|
||||||
"xml", "jackson", "jsoup", "markdown", "network", "httpd",
|
"xml", "jackson", "jsoup", "markdown", "network", "httpd",
|
||||||
"properties",
|
"properties", "serial-io",
|
||||||
"mustache", "thymeleaf", "locale", "quartz", "sysinfo",
|
"mustache", "thymeleaf", "locale", "quartz", "sysinfo",
|
||||||
"imaging"
|
"imaging", "stream", "sound"
|
||||||
)
|
)
|
||||||
|
|||||||
14
sound/build.gradle.kts
Normal file
14
sound/build.gradle.kts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
}
|
||||||
34
sound/src/main/java/kr/pe/elex/examples/Converter.java
Normal file
34
sound/src/main/java/kr/pe/elex/examples/Converter.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Converter {
|
||||||
|
public static void main(String... args) throws UnsupportedAudioFileException, IOException {
|
||||||
|
File inFile = new File("test_out.wav");
|
||||||
|
File outFile = new File("test_out.au");
|
||||||
|
|
||||||
|
AudioInputStream inputStream = AudioSystem.getAudioInputStream(inFile);
|
||||||
|
AudioFormat outFormat = new AudioFormat(8000, 8, 1, true, false);
|
||||||
|
|
||||||
|
if (AudioSystem.isConversionSupported(outFormat, inputStream.getFormat()) &&
|
||||||
|
AudioSystem.isFileTypeSupported(AudioFileFormat.Type.AU, inputStream)) {
|
||||||
|
AudioInputStream lowResInputStream = AudioSystem
|
||||||
|
.getAudioInputStream(outFormat, inputStream);
|
||||||
|
|
||||||
|
AudioSystem.write(lowResInputStream, AudioFileFormat.Type.AU, outFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
56
sound/src/main/java/kr/pe/elex/examples/Example.java
Normal file
56
sound/src/main/java/kr/pe/elex/examples/Example.java
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Example {
|
||||||
|
public static void main(String... args) throws LineUnavailableException {
|
||||||
|
Console.writeLine("# Audio file formats");
|
||||||
|
for (AudioFileFormat.Type type : AudioSystem.getAudioFileTypes()) {
|
||||||
|
Console.writeLine("{} / {}", type.toString(), type.getExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.writeLine("# Audio mixers");
|
||||||
|
for (Mixer.Info info : AudioSystem.getMixerInfo()) {
|
||||||
|
Console.writeLine("{} / {} / {}", info.getName(), info.getDescription(), info.getVendor());
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.writeLine("# Getting a Line from mixer");
|
||||||
|
Mixer mixer = AudioSystem.getMixer(AudioSystem.getMixerInfo()[1]);
|
||||||
|
//mixer.sy
|
||||||
|
for (Line.Info info : mixer.getSourceLineInfo()) {
|
||||||
|
Console.writeLine("{}", info);
|
||||||
|
if (mixer.isLineSupported(info)) {
|
||||||
|
Line line = mixer.getLine(info);
|
||||||
|
//line.open();
|
||||||
|
//line.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Console.writeLine("# Getting a Line from Audio System");
|
||||||
|
AudioFormat audioFormat = new AudioFormat(441000,16,2, false,true);
|
||||||
|
TargetDataLine line;
|
||||||
|
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
|
||||||
|
if (AudioSystem.isLineSupported(info)) {
|
||||||
|
line = (TargetDataLine) AudioSystem.getLine(info);
|
||||||
|
line.open(audioFormat);
|
||||||
|
line.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.writeLine("# Getting a Port from Audio System");
|
||||||
|
if (AudioSystem.isLineSupported(Port.Info.SPEAKER)) {
|
||||||
|
Port speakerPort = (Port) AudioSystem.getLine(Port.Info.SPEAKER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
sound/src/main/java/kr/pe/elex/examples/Playback.java
Normal file
65
sound/src/main/java/kr/pe/elex/examples/Playback.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Playback {
|
||||||
|
|
||||||
|
public static void main(String... args) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
|
||||||
|
playback();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void playback() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
|
||||||
|
AudioInputStream inputStream = AudioSystem.getAudioInputStream(Objects.requireNonNull(ClassLoader.
|
||||||
|
getSystemResourceAsStream("alarm_gentle.wav")));
|
||||||
|
|
||||||
|
SourceDataLine line = AudioSystem.getSourceDataLine(inputStream.getFormat());
|
||||||
|
line.open();
|
||||||
|
line.start();
|
||||||
|
line.addLineListener(event -> {
|
||||||
|
if (event.getType().equals(LineEvent.Type.OPEN)) {
|
||||||
|
|
||||||
|
} else if (event.getType().equals(LineEvent.Type.START)) {
|
||||||
|
|
||||||
|
} else if (event.getType().equals(LineEvent.Type.STOP)) {
|
||||||
|
|
||||||
|
} else if (event.getType().equals(LineEvent.Type.CLOSE)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
byte[] buffer = new byte[32];
|
||||||
|
int numRead = 0;
|
||||||
|
while ((numRead = inputStream.read(buffer, 0, buffer.length)) > 0) {
|
||||||
|
log.debug("read: {}", numRead);
|
||||||
|
line.write(buffer, 0, numRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
inputStream.close();
|
||||||
|
line.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void playbackClip() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
|
||||||
|
Clip clip = AudioSystem.getClip();
|
||||||
|
clip.open(AudioSystem.getAudioInputStream(Objects.requireNonNull(ClassLoader.
|
||||||
|
getSystemResourceAsStream("alarm_gentle.wav"))));
|
||||||
|
//clip.loop(3);
|
||||||
|
clip.start();
|
||||||
|
|
||||||
|
//clip.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
63
sound/src/main/java/kr/pe/elex/examples/RecordAudio.java
Normal file
63
sound/src/main/java/kr/pe/elex/examples/RecordAudio.java
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class RecordAudio {
|
||||||
|
static boolean isRunning = true;
|
||||||
|
|
||||||
|
public static void main(String... args) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
|
||||||
|
|
||||||
|
TargetDataLine line;
|
||||||
|
AudioFormat audioFormat = new AudioFormat(44100, 16, 2, true, true);
|
||||||
|
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
|
||||||
|
if (AudioSystem.isLineSupported(info)) {
|
||||||
|
line = AudioSystem.getTargetDataLine(audioFormat);
|
||||||
|
log.debug("{}", line.getLineInfo());
|
||||||
|
line.open(audioFormat);
|
||||||
|
line.start();
|
||||||
|
|
||||||
|
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
service.schedule(() -> isRunning = false, 5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[32];
|
||||||
|
|
||||||
|
while (isRunning) {
|
||||||
|
int numRead = line.read(buffer, 0, buffer.length);
|
||||||
|
os.write(buffer, 0, numRead);
|
||||||
|
|
||||||
|
log.debug("{}", line.getLevel());
|
||||||
|
}
|
||||||
|
log.debug("end of loop");
|
||||||
|
|
||||||
|
File file = new File("test_out.wav");
|
||||||
|
AudioInputStream is = new AudioInputStream(new ByteArrayInputStream(os.toByteArray()),
|
||||||
|
audioFormat, os.size()/2/2);
|
||||||
|
|
||||||
|
//AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(new File(""));
|
||||||
|
|
||||||
|
AudioSystem.write(is, AudioFileFormat.Type.WAVE, file);
|
||||||
|
|
||||||
|
os.close();
|
||||||
|
line.close();
|
||||||
|
service.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class SignalProcessing {
|
||||||
|
|
||||||
|
public static void main(String... args)
|
||||||
|
throws UnsupportedAudioFileException, IOException, LineUnavailableException {
|
||||||
|
|
||||||
|
for (Mixer.Info mixerInfo : AudioSystem.getMixerInfo()) {
|
||||||
|
Mixer mixer = AudioSystem.getMixer(mixerInfo);
|
||||||
|
Console.writeLine("MIXER: {}", mixerInfo);
|
||||||
|
for (Control control : mixer.getControls()){
|
||||||
|
Console.writeLine("CONTROL: {}", control.toString());
|
||||||
|
}
|
||||||
|
for (Line.Info info : mixer.getSourceLineInfo()) {
|
||||||
|
Console.writeLine("SOURCE LINE: {}" , info);
|
||||||
|
Line line = mixer.getLine(info);
|
||||||
|
for (Control control : line.getControls()){
|
||||||
|
Console.writeLine("CONTROL: {}", control.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Line.Info info : mixer.getTargetLineInfo()) {
|
||||||
|
Console.writeLine("TARGET LINE: {}" , info);
|
||||||
|
Line line = mixer.getLine(info);
|
||||||
|
for (Control control : line.getControls()){
|
||||||
|
Console.writeLine("CONTROL: {}", control.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*AudioInputStream inputStream = AudioSystem.getAudioInputStream(Objects.requireNonNull(ClassLoader.
|
||||||
|
getSystemResourceAsStream("alarm_gentle.wav")));
|
||||||
|
SourceDataLine src = AudioSystem.getSourceDataLine(inputStream.getFormat());
|
||||||
|
src.open();
|
||||||
|
src.start();
|
||||||
|
|
||||||
|
Mixer mixer = AudioSystem.getMixer(AudioSystem.getMixerInfo()[1]);
|
||||||
|
Console.writeLine(mixer.getLineInfo());
|
||||||
|
Port line = (Port) mixer.getLine(Port.Info.LINE_IN);
|
||||||
|
line.open();
|
||||||
|
for (Control ctrl : line.getControls()) {
|
||||||
|
Console.writeLine(ctrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatControl volumeCtrl = (FloatControl) mixer.getControl(FloatControl.Type.VOLUME);
|
||||||
|
volumeCtrl.setValue(0);
|
||||||
|
byte[] buffer = new byte[64];
|
||||||
|
int numRead = 0;
|
||||||
|
float dVol = 0.f;
|
||||||
|
while ((numRead = inputStream.read(buffer, 0, buffer.length)) > 0) {
|
||||||
|
log.debug("vol: {}", volumeCtrl.getValue());
|
||||||
|
src.write(buffer, 0, numRead);
|
||||||
|
if (volumeCtrl.getValue()<=volumeCtrl.getMinimum()) {
|
||||||
|
dVol = 0.01f;
|
||||||
|
} else if (volumeCtrl.getValue()>=volumeCtrl.getMaximum()){
|
||||||
|
dVol = -0.01f;
|
||||||
|
}
|
||||||
|
volumeCtrl.setValue(volumeCtrl.getValue()+dVol);
|
||||||
|
}
|
||||||
|
|
||||||
|
inputStream.close();
|
||||||
|
src.close();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
BIN
sound/src/main/resources/alarm_gentle.wav
Executable file
BIN
sound/src/main/resources/alarm_gentle.wav
Executable file
Binary file not shown.
BIN
sound/src/main/resources/ringtone_minimal.wav
Executable file
BIN
sound/src/main/resources/ringtone_minimal.wav
Executable file
Binary file not shown.
14
stream/build.gradle.kts
Normal file
14
stream/build.gradle.kts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
runtimeOnly ("org.xerial:sqlite-jdbc:3.36.0.1")
|
||||||
|
}
|
||||||
27
stream/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
27
stream/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Sample {
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Stream<String> toStream(List<String> list) {
|
||||||
|
return null == list ? Stream.empty() : list.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
92
stream/src/test/java/kr/pe/elex/examples/SampleTest.java
Normal file
92
stream/src/test/java/kr/pe/elex/examples/SampleTest.java
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.*;
|
||||||
|
|
||||||
|
class SampleTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void create_stream() {
|
||||||
|
Stream<String> stream1 = Stream.empty();
|
||||||
|
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
Stream<String> stream2 = list.stream();
|
||||||
|
|
||||||
|
Set<String> set = new HashSet<>();
|
||||||
|
Stream<String> stream3 = set.stream();
|
||||||
|
|
||||||
|
Collection<String> collection = new HashSet<>();
|
||||||
|
Stream<String> stream4 = collection.stream();
|
||||||
|
|
||||||
|
Stream<String> stream5 = Stream.of("1", "2", "3");
|
||||||
|
|
||||||
|
String[] strings = new String[]{"1", "2", "3"};
|
||||||
|
Stream<String> stream6 = Stream.of(strings);
|
||||||
|
stream6 = Arrays.stream(strings);
|
||||||
|
|
||||||
|
Stream<String> stream7 = Stream.<String>builder()
|
||||||
|
.add("1").add("2").add("3")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Stream<String> stream8 = Stream.generate(new Supplier<String>() {
|
||||||
|
private int idx = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get() {
|
||||||
|
return strings[idx++];
|
||||||
|
}
|
||||||
|
}).limit(strings.length);
|
||||||
|
|
||||||
|
Stream<String> stream9 = Stream.iterate(strings[0], new Predicate<String>() {
|
||||||
|
@Override
|
||||||
|
public boolean test(String s) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, new UnaryOperator<String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(String s) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_2() throws IOException {
|
||||||
|
IntStream stream1 = IntStream.range(0, 10);
|
||||||
|
IntStream stream2 = IntStream.rangeClosed(0, 10);
|
||||||
|
|
||||||
|
LongStream stream3 = LongStream.range(0, 10);
|
||||||
|
DoubleStream stream4 = DoubleStream.empty();
|
||||||
|
|
||||||
|
IntStream stream5 = new Random().ints().limit(10);
|
||||||
|
|
||||||
|
Stream<String> stream6 = "Hello\nWorld".lines();
|
||||||
|
IntStream stream7 = "Hello".chars();
|
||||||
|
Stream<String> stream8 = Pattern.compile(", ").splitAsStream("1, 2, 3");
|
||||||
|
|
||||||
|
Path path = Paths.get("");
|
||||||
|
Stream<String> stream9 = Files.lines(path, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
BIN
stream/test.db
Normal file
BIN
stream/test.db
Normal file
Binary file not shown.
BIN
test_out.au
Normal file
BIN
test_out.au
Normal file
Binary file not shown.
BIN
test_out.wav
Normal file
BIN
test_out.wav
Normal file
Binary file not shown.
14
webcam/build.gradle.kts
Normal file
14
webcam/build.gradle.kts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("com.github.sarxos:webcam-capture:0.3.12")
|
||||||
|
}
|
||||||
91
webcam/src/main/java/kr/pe/elex/examples/WebcamSample.java
Normal file
91
webcam/src/main/java/kr/pe/elex/examples/WebcamSample.java
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.github.sarxos.webcam.Webcam;
|
||||||
|
import com.github.sarxos.webcam.WebcamPanel;
|
||||||
|
import com.github.sarxos.webcam.WebcamResolution;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class WebcamSample {
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
JFrame jFrame = new JFrame("Web Cam");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
jFrame.setContentPane(new MyPanel());
|
||||||
|
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyPanel extends JPanel {
|
||||||
|
private Webcam webcam;
|
||||||
|
|
||||||
|
MyPanel() {
|
||||||
|
super();
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
webcam = Webcam.getDefault();
|
||||||
|
Dimension resolution = WebcamResolution.QVGA.getSize();
|
||||||
|
webcam.setViewSize(resolution);
|
||||||
|
webcam.open();
|
||||||
|
|
||||||
|
WebcamPanel panel = new WebcamPanel(webcam);
|
||||||
|
panel.setFPSDisplayed(true);
|
||||||
|
panel.setAntialiasingEnabled(true);
|
||||||
|
panel.setSize(resolution);
|
||||||
|
|
||||||
|
JButton btnCapture = new JButton("Capture");
|
||||||
|
btnCapture.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
BufferedImage image = webcam.getImage();
|
||||||
|
ImageIO.write(image, "jpg", new File("out/capture.jpg"));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JButton btnResolution = new JButton("Resolutions");
|
||||||
|
btnResolution.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
for (Dimension item : webcam.getDevice().getResolutions()) {
|
||||||
|
System.out.println(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JToolBar jToolBar = new JToolBar();
|
||||||
|
jToolBar.add(btnCapture);
|
||||||
|
jToolBar.add(btnResolution);
|
||||||
|
|
||||||
|
add(panel, BorderLayout.CENTER);
|
||||||
|
add(jToolBar, BorderLayout.NORTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user