处理MQTT消息

This commit is contained in:
2025-11-08 09:38:19 +08:00
parent ee85961eeb
commit 33d6108172
13 changed files with 1020 additions and 0 deletions

View File

@ -0,0 +1,52 @@
package com.fuyuanshen.app.domain.vo;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) throws IOException {
String[] availableIDs = TimeZone.getAvailableIDs();
for (String id : availableIDs) {
System.out.println(id);
}
byte[] data = "hello, world!".getBytes(StandardCharsets.UTF_8);
try (CountInputStream input = new CountInputStream(new ByteArrayInputStream(data))) {
int n;
while ((n = input.read()) != -1) {
System.out.println((char)n);
}
System.out.println("Total read " + input.getBytesRead() + " bytes");
}
}
}
class CountInputStream extends FilterInputStream {
private int count = 0;
CountInputStream(InputStream in) {
super(in);
}
public int getBytesRead() {
return this.count;
}
public int read() throws IOException {
int n = in.read();
if (n != -1) {
this.count ++;
}
return n;
}
public int read(byte[] b, int off, int len) throws IOException {
int n = in.read(b, off, len);
if (n != -1) {
this.count += n;
}
return n;
}
}