当前位置: 首页 > news >正文

输入输出流、字符字节流、NIO

1、对输入输出流、字符字节流的学习,以之前做的批量下载功能为例

批量下载指的是,将多个文件打包到zip文件中,然后下载该zip文件。

1.1下载网络上的文件

代码参考如下:

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;public class MultiDownloadByUrlTest {public static void main(String[] args) throws IOException {//如果zip文件不存在则创建zipString localZipFile = "D:/temp/testUrl.zip" ;File file = new File(localZipFile);if(!file.exists()){file.createNewFile();}ZipOutputStream out = new ZipOutputStream(new FileOutputStream(localZipFile));byte[] buffer = new byte[1024];//要批量下载的文件数组String[] urls = new String[] {"http://www.baidu.com/img/PCfb_5bf082d29588c07f842ccde3f97243ea.png","https://img-home.csdnimg.cn/images/20201124032511.png"};//依次获取批量下载的文件for(int i =0; i<urls.length;i++){//从数据库中获取文件的路径和文件名,并放入zip文件中String urlFile = urls[i];out.putNextEntry(new ZipEntry(i+".png"));int len;URL url = new URL(urlFile);URLConnection conn = url.openConnection();InputStream inStream = conn.getInputStream();//读入需要下载的文件的内容,打包到zip文件while ((len = inStream.read(buffer)) > 0) {out.write(buffer, 0, len);}out.closeEntry();inStream.close();}out.close();}}

1.2、下载磁盘中的多个文件到zip文件中

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;public class MultiDownloadTest {public static void main(String[] args) throws IOException {//如果zip文件不存在则创建zipString localZipFile = "D:/temp/test.zip" ;File file = new File(localZipFile);if(!file.exists()){file.createNewFile();}ZipOutputStream out = new ZipOutputStream(new FileOutputStream(localZipFile));//要批量下载的文件数组String[] ids = new String[] {"11.docx","22.xlsx"};byte[] buffer = new byte[1024];//依次获取批量下载的文件for(int i =0; i<ids.length;i++){String fileName = ids[i];out.putNextEntry(new ZipEntry(fileName));int len;FileInputStream inStream = new FileInputStream(new File("D:/temp/"+fileName));//读入需要下载的文件的内容,打包到zip文件while ((len = inStream.read(buffer)) > 0) {out.write(buffer, 0, len);}out.closeEntry();inStream.close();}out.close();}}

1.3编写接口,下载该zip文件

Controller类代码如下:

package com.hmblogs.backend.controller;import com.hmblogs.backend.util.MultiDownloadTest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;@RestController
@Slf4j
public class FileController {/*** get方式下载zip文件* @return*/@GetMapping(value = "/downloadZipByGet")public void downloadZipByGet(HttpServletRequest request,HttpServletResponse response) throws IOException {log.info("downloadZipByGet prepare begin.");MultiDownloadTest.preMultiDownload();log.info("downloadZipByGet prepare end.");log.info("downloadZipByGet begin.");String zipFileName = "D:/temp/test.zip";InputStream is = new FileInputStream(new File(zipFileName));// 设置response参数,可以打开下载页面response.reset();response.setContentType("application/octet-stream;charset=utf-8");response.setHeader("Access-Control-Expose-Headers", "content-disposition");response.setHeader("Content-Disposition", "attachment;filename=test.zip");ServletOutputStream out = response.getOutputStream();BufferedInputStream bis = null;BufferedOutputStream bos = null;try {bis = new BufferedInputStream(is);bos = new BufferedOutputStream(out);byte[] buff = new byte[2048];int bytesRead;while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {bos.write(buff, 0, bytesRead);}log.info("downloadZipByGet end.");} catch (final IOException e) {log.error("downloadZipByGet errors, reason:{}", e.getMessage());} finally {if (bis != null){bis.close();}if (is != null){is.close();}if (bos != null){bos.close();}if (out != null){out.close();}}// 用后删除临时用途的zip文件File fileTempZip = new File(zipFileName);if(fileTempZip.exists()){fileTempZip.delete();}}/*** post方式下载zip文件* @return*/@RequestMapping(value = "/downloadZipByPost",method = RequestMethod.POST)public void downloadZipByPost(){}}

工具类MultiDownloadTest.java代码如下:

package com.hmblogs.backend.util;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;public class MultiDownloadTest {public static void preMultiDownload() throws IOException {//如果zip文件不存在则创建zipString localZipFile = "D:/temp/test.zip" ;File file = new File(localZipFile);if(!file.exists()){file.createNewFile();}ZipOutputStream out = new ZipOutputStream(new FileOutputStream(localZipFile));//要批量下载的文件数组String[] ids = new String[] {"11.docx","22.xlsx"};byte[] buffer = new byte[1024];//依次获取批量下载的文件for(int i =0; i<ids.length;i++){String fileName = ids[i];out.putNextEntry(new ZipEntry(fileName));int len;FileInputStream inStream = new FileInputStream(new File("D:/temp/"+fileName));//读入需要下载的文件的内容,打包到zip文件while ((len = inStream.read(buffer)) > 0) {out.write(buffer, 0, len);}out.closeEntry();inStream.close();}out.close();}}

1.4访问接口

http://localhost:8080/backend/downloadZipByGet

下载了文件,能正常打开,且文件都是正常的。

二、学习NIO

参考Java之NIO基本简介_java_脚本之家

2.1开发一个简单的服务端接收客户端发过来的消息的功能

服务端Server.java代码如下:


import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.util.Iterator;
public class Server {public static void main(String[] args) {try {//1.获取管道ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();//2.设置非阻塞模式serverSocketChannel.configureBlocking(false);//3.绑定端口serverSocketChannel.bind(new InetSocketAddress(8888));//4.获取选择器Selector selector = Selector.open();//5.将通道注册到选择器上,并且开始指定监听的接收事件serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);//6.轮询已经就绪的事件while (selector.select() > 0){System.out.println("开启事件处理");//7.获取选择器中所有注册的通道中已准备好的事件Iterator<SelectionKey> it = selector.selectedKeys().iterator();//8.开始遍历事件while (it.hasNext()){SelectionKey selectionKey = it.next();//9.判断这个事件具体是啥if (selectionKey.isAcceptable()){System.out.println("isAcceptable--->"+selectionKey);//10.获取当前接入事件的客户端通道SocketChannel socketChannel = serverSocketChannel.accept();//11.切换成非阻塞模式socketChannel.configureBlocking(false);//12.将本客户端注册到选择器socketChannel.register(selector,SelectionKey.OP_READ);}else if (selectionKey.isReadable()){System.out.println("isReadable--->"+selectionKey);//13.获取当前选择器上的读SocketChannel socketChannel = (SocketChannel) selectionKey.channel();//14.读取ByteBuffer buffer = ByteBuffer.allocate(1024);int len;while ((len = socketChannel.read(buffer)) > 0){buffer.flip();System.out.println(new String(buffer.array(),0,len));//清除之前的数据(覆盖写入)buffer.clear();}}//15.处理完毕后,移除当前事件it.remove();}}} catch (IOException e) {e.printStackTrace();}}
}

客户端Client.java代码如下:

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;
public class Client {public static void main(String[] args) {try {SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("127.0.0.1",8888));socketChannel.configureBlocking(false);ByteBuffer buffer = ByteBuffer.allocate(1024);Scanner scanner = new Scanner(System.in);while (true){System.out.print("请输入:");String msg = scanner.nextLine();buffer.put(msg.getBytes());buffer.flip();socketChannel.write(buffer);buffer.clear();}} catch (IOException e) {e.printStackTrace();}}
}

运行Server

然后运行Client

在Client输入wwww

然后看到Server打印如下内容:

开启事件处理
isAcceptable--->sun.nio.ch.SelectionKeyImpl@42110406
开启事件处理
isReadable--->sun.nio.ch.SelectionKeyImpl@531d72ca
wwww

可以看到, 这时先开启了isAcceptable事件处理,然后开启了isReadable事件处理。

然后再在Client输入qqqq

然后看到Server打印如下内容:

开启事件处理
isReadable--->sun.nio.ch.SelectionKeyImpl@531d72ca
qqqq

这时只开启了isReadable这样的事件处理,不用再开启isAcceptable事件处理

server控制台截图如下

client的控制台如下: 

2.2开发网络编程应用实例-群聊系统

需求:进一步理解 NIO 非阻塞网络编程机制,实现多人群聊

 编写一个 NIO 群聊系统,实现客户端与客户端的通信需求(非阻塞)

服务器端:可以监测用户上线,离线,并实现消息转发功能

客户端:通过 channel 可以无阻塞发送消息给其它所有客户端用户,同时可以接受其它客户端用户通过服务端转发来的消息

Server.java代码如下:


import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.util.Iterator;
/****/
public class Server {//定义属性private Selector selector;private ServerSocketChannel ssChannel;private static final int PORT = 9999;//构造器//初始化工作public Server() {try {// 1、获取通道ssChannel = ServerSocketChannel.open();// 2、切换为非阻塞模式ssChannel.configureBlocking(false);// 3、绑定连接的端口ssChannel.bind(new InetSocketAddress(PORT));// 4、获取选择器Selectorselector = Selector.open();// 5、将通道都注册到选择器上去,并且开始指定监听接收事件ssChannel.register(selector , SelectionKey.OP_ACCEPT);}catch (IOException e) {e.printStackTrace();}}//监听public void listen() {System.out.println("监听线程:" + Thread.currentThread().getName());try {while (selector.select() > 0){// 7、获取选择器中的所有注册的通道中已经就绪好的事件Iterator<SelectionKey> it = selector.selectedKeys().iterator();// 8、开始遍历这些准备好的事件while (it.hasNext()){// 提取当前这个事件SelectionKey sk = it.next();// 9、判断这个事件具体是什么if(sk.isAcceptable()){// 10、直接获取当前接入的客户端通道SocketChannel schannel = ssChannel.accept();// 11 、切换成非阻塞模式schannel.configureBlocking(false);// 12、将本客户端通道注册到选择器System.out.println(schannel.getRemoteAddress() + " 上线 ");schannel.register(selector , SelectionKey.OP_READ);//提示}else if(sk.isReadable()){//处理读 (专门写方法..)readData(sk);}it.remove(); // 处理完毕之后需要移除当前事件}}}catch (Exception e) {e.printStackTrace();}finally {//发生异常处理....}}//读取客户端消息private void readData(SelectionKey key) {//获取关联的channelSocketChannel channel = null;try {//得到channelchannel = (SocketChannel) key.channel();//创建bufferByteBuffer buffer = ByteBuffer.allocate(1024);int count = channel.read(buffer);//根据count的值做处理if(count > 0) {//把缓存区的数据转成字符串String msg = new String(buffer.array());//输出该消息System.out.println("来自客户端---> " + msg);//向其它的客户端转发消息(去掉自己), 专门写一个方法来处理sendInfoToOtherClients(msg, channel);}}catch (IOException e) {try {System.out.println(channel.getRemoteAddress() + " 离线了..");e.printStackTrace();//取消注册key.cancel();//关闭通道channel.close();}catch (IOException e2) {e2.printStackTrace();;}}}//转发消息给其它客户(通道)private void sendInfoToOtherClients(String msg, SocketChannel self ) throws  IOException{System.out.println("服务器转发消息中...");System.out.println("服务器转发数据给客户端线程: " + Thread.currentThread().getName());//遍历 所有注册到selector 上的 SocketChannel,并排除 selffor(SelectionKey key: selector.keys()) {//通过 key  取出对应的 SocketChannelChannel targetChannel = key.channel();//排除自己if(targetChannel instanceof  SocketChannel && targetChannel != self) {//转型SocketChannel dest = (SocketChannel)targetChannel;//将msg 存储到bufferByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());//将buffer 的数据写入 通道dest.write(buffer);}}}public static void main(String[] args) {//创建服务器对象Server groupChatServer = new Server();groupChatServer.listen();}
}

Client.java代码如下:


import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Scanner;
public class Client {//定义相关的属性private final String HOST = "127.0.0.1"; // 服务器的ipprivate final int PORT = 9999; //服务器端口private Selector selector;private SocketChannel socketChannel;private String username;//构造器, 完成初始化工作public Client() throws IOException {selector = Selector.open();//连接服务器socketChannel = socketChannel.open(new InetSocketAddress("127.0.0.1", PORT));//设置非阻塞socketChannel.configureBlocking(false);//将channel 注册到selectorsocketChannel.register(selector, SelectionKey.OP_READ);//得到usernameusername = socketChannel.getLocalAddress().toString().substring(1);System.out.println(username + " is ok...");}//向服务器发送消息public void sendInfo(String info) {info = username + " 说:" + info;try {socketChannel.write(ByteBuffer.wrap(info.getBytes()));}catch (IOException e) {e.printStackTrace();}}//读取从服务器端回复的消息public void readInfo() {try {int readChannels = selector.select();if(readChannels > 0) {//有可以用的通道Iterator<SelectionKey> iterator = selector.selectedKeys().iterator();while (iterator.hasNext()) {SelectionKey key = iterator.next();if(key.isReadable()) {//得到相关的通道SocketChannel sc = (SocketChannel) key.channel();//得到一个BufferByteBuffer buffer = ByteBuffer.allocate(1024);//读取sc.read(buffer);//把读到的缓冲区的数据转成字符串String msg = new String(buffer.array());System.out.println(msg.trim());}}iterator.remove(); //删除当前的selectionKey, 防止重复操作} else {//System.out.println("没有可以用的通道...");}}catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) throws Exception {//启动我们客户端Client chatClient = new Client();//启动一个线程, 每个3秒,读取从服务器发送数据new Thread() {public void run() {while (true) {chatClient.readInfo();try {Thread.currentThread().sleep(3000);}catch (InterruptedException e) {e.printStackTrace();}}}}.start();//发送数据给服务器端Scanner scanner = new Scanner(System.in);while (scanner.hasNextLine()) {System.out.print("请输入:");String s = scanner.nextLine();chatClient.sendInfo(s);}}
}

Client22.java代码如下:就是Client.java的代码复制一份,改下文件名而已。


import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Scanner;public class Client22 {//定义相关的属性private final String HOST = "127.0.0.1"; // 服务器的ipprivate final int PORT = 9999; //服务器端口private Selector selector;private SocketChannel socketChannel;private String username;//构造器, 完成初始化工作public Client22() throws IOException {selector = Selector.open();//连接服务器socketChannel = socketChannel.open(new InetSocketAddress("127.0.0.1", PORT));//设置非阻塞socketChannel.configureBlocking(false);//将channel 注册到selectorsocketChannel.register(selector, SelectionKey.OP_READ);//得到usernameusername = socketChannel.getLocalAddress().toString().substring(1);System.out.println(username + " is ok...");}//向服务器发送消息public void sendInfo(String info) {info = username + " 说:" + info;try {socketChannel.write(ByteBuffer.wrap(info.getBytes()));}catch (IOException e) {e.printStackTrace();}}//读取从服务器端回复的消息public void readInfo() {try {int readChannels = selector.select();if(readChannels > 0) {//有可以用的通道Iterator<SelectionKey> iterator = selector.selectedKeys().iterator();while (iterator.hasNext()) {SelectionKey key = iterator.next();if(key.isReadable()) {//得到相关的通道SocketChannel sc = (SocketChannel) key.channel();//得到一个BufferByteBuffer buffer = ByteBuffer.allocate(1024);//读取sc.read(buffer);//把读到的缓冲区的数据转成字符串String msg = new String(buffer.array());System.out.println(msg.trim());}}iterator.remove(); //删除当前的selectionKey, 防止重复操作} else {//System.out.println("没有可以用的通道...");}}catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) throws Exception {//启动我们客户端Client22 chatClient = new Client22();//启动一个线程, 每个3秒,读取从服务器发送数据new Thread() {public void run() {while (true) {chatClient.readInfo();try {Thread.currentThread().sleep(3000);}catch (InterruptedException e) {e.printStackTrace();}}}}.start();//发送数据给服务器端Scanner scanner = new Scanner(System.in);while (scanner.hasNextLine()) {System.out.print("请输入:");String s = scanner.nextLine();chatClient.sendInfo(s);}}
}

启动Server、Client、Client22后,在Client输入内容、在Client22输入内容后,对3个控制台截图如下

Server控制台截图如下:

Client控制台如下:

Client22控制台如下:

 

简单的需求目的达到了。 

相关文章:

输入输出流、字符字节流、NIO

1、对输入输出流、字符字节流的学习&#xff0c;以之前做的批量下载功能为例 批量下载指的是&#xff0c;将多个文件打包到zip文件中&#xff0c;然后下载该zip文件。 1.1下载网络上的文件 代码参考如下&#xff1a; import java.io.*; import java.net.URL; import java.n…...

js中对数字,超大金额(千位符,小数点)格式化处理

前言 这个问题的灵感来自线上一个小bug&#xff0c;前两天刚看完同事写的代码&#xff0c;对数字类型处理的很好&#xff0c;之前一直都是用正则和toFixed(2)处理数字相关&#xff0c;后面发现使用numeral.js处理更完美。 对于下面这种数据的处理&#xff0c;你能想到几种方法…...

Android 打开热点2.4G系统重启解决

Android 打开热点2.4G系统重启解决 文章目录 Android 打开热点2.4G系统重启解决一、前言二、过程分析1、Android 设备开机后第一次打开热点2.4G系统重启2、日志分析3、设备重启原因 三、解决方法四、其他1、wifi/有线网 代理信息也可能导致系统重启2、Android13 热点默认5G频道…...

全链路压力测试有哪些主要作用

全链路压力测试是在软件开发和维护过程中不可或缺的一环&#xff0c;尤其在复杂系统和高并发场景下显得尤为重要。下面将详细介绍全链路压力测试的主要作用。 一、全链路压力测试概述 全链路压力测试是指对软件系统的全部组件(包括前端、后端、数据库、网络、中间件等)在高负载…...

【python基础教程】print输出函数和range()函数的正确使用方式

嗨喽&#xff0c;大家好呀~这里是爱看美女的茜茜呐 print()有多个参数&#xff0c;参数个数不固定。 有四个关键字参数&#xff08;sep end file flush&#xff09;&#xff0c;这四个关键字参数都有默认值。 print作用是将objects的内容输出到file中&#xff0c;objects中的…...

LeetCode255.用队列实现栈

题目传送门&#xff1a;Leetcode255.用队列实现栈 请你仅使用两个队列实现一个后入先出&#xff08;LIFO&#xff09;的栈&#xff0c;并支持普通栈的全部四种操作&#xff08;push、top、pop 和 empty&#xff09;。 实现 MyStack 类&#xff1a; void push(int x) 将元素 x 压…...

PHPStudy快速搭建网站并结合内网穿透远程访问本地站点

文章目录 [toc]使用工具1. 本地搭建web网站1.1 下载phpstudy后解压并安装1.2 打开默认站点&#xff0c;测试1.3 下载静态演示站点1.4 打开站点根目录1.5 复制演示站点到站网根目录1.6 在浏览器中&#xff0c;查看演示效果。 2. 将本地web网站发布到公网2.1 安装cpolar内网穿透2…...

AI嵌入式K210项目(1)-芯片开发板介绍

系列文章目录 在人工智能大潮滚滚而来的时代&#xff0c;作为一个从事嵌入式行业多年的程序猿倍感焦虑&#xff0c;有被替代的焦虑&#xff0c;也有跟不上新技术步伐的无奈&#xff0c;本系列文章将介绍一个从硬件设计到ai训练、最后到模型部署的完整案例&#xff1b;第一阶段…...

Blazor中使用impress.js

impress.js是什么&#xff1f; 你想在浏览器中做PPT吗&#xff1f;比如在做某些类似于PPT自动翻页&#xff0c;局部放大之类&#xff0c;炫酷无比。 在Blazor中&#xff0c;几经尝试&#xff0c;用以下方法可以实现。写文不易&#xff0c;请点赞、收藏、关注&#xff0c;并在转…...

ros2 ubuntu 20.04 安装 foxy

设置区域设置 确保您有一个支持UTF-8. 如果您处于最小环境&#xff08;例如 docker 容器&#xff09;中&#xff0c;则区域设置可能是最小的&#xff0c;例如POSIX. 我们使用以下设置进行测试。但是&#xff0c;如果您使用不同的 UTF-8 支持的区域设置&#xff0c;应该没问题。…...

Blazor 错误笔记

1. 运行时问题 Microsoft.NETCore.App.Runtime.Mono.browser-wasm Microsoft.NETCore.App.Runtime.Mono.browser-wasm 是一个 .NET Core 运行时的包&#xff0c;用于在浏览器中运行 .NET Core 应用程序。它是针对 WebAssembly 架构的 .NET Core 运行时&#xff0c;可以在浏览…...

【深度学习1对1指导】

...

XUbuntu22.04之快速复制绝对路径(二百零五)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 优质专栏&#xff1a;多媒…...

21、Kubernetes核心技术 - 高可用集群搭建(kubeadm+keepalived+haproxy)

目录 一、简介 二、高可用集群架构说明 三、部署环境说明 四、高可用集群搭建 (1)、初始化所有节点 (2)、修改host文件 (3)、调整内核参数 (4)、所有节点安装Docker (4-1)、配置 docker 的阿里 yum 源 (4-2)、yum 安装 docker (4-3)、配置 docker 的镜像源 (4-4)…...

使用SpringDataRedis操作Redis

Redis的java客户端 jedisLettuceSpring Data Redis Spring Data redis 是Spring的一部分&#xff0c;对 Redis 底层开发包进行了高度封装。在Spring项目中&#xff0c;可以使用Spring Data Redis来简化操作。 Spring Data Redis使用方式 操作步骤&#xff1a; 导入Spring …...

PyCharm社区版如何创建Django项目并运行

一、配置Django环境 1、使用PyCharm打开一个普通的Python项目 2、为该项目配置Django环境 &#xff08;1&#xff09;点击"File"-"Settings" &#xff08;2&#xff09;点击"Project:项目名"-"Python Interpreter"-"号" &…...

深度探讨鸿蒙工程师面试题

深度探讨鸿蒙工程师面试题 第一部分&#xff1a;引言 鸿蒙&#xff08;HarmonyOS&#xff09;作为华为推出的全场景分布式操作系统&#xff0c;引领着未来智能化时代的潮流。鸿蒙工程师在这一创新性领域中扮演着至关重要的角色。本文将深入研究一系列鸿蒙工程师面试题&#x…...

python数据结构堆栈

堆 堆是一种树形结构&#xff1a;满足两个主要性质 堆是一种完全二叉树&#xff1a;堆中所有层级除了最后一层都是完全填满的&#xff0c;且最后一层的节点都是向左排列堆中的任意节点都不大于&#xff08;或不小于&#xff09;其子节点的值&#xff0c;这也是堆的属性 impo…...

从网页连接socket服务器和I/O

1.i/o InputStream和InputStreamReader是Java I/O类库中的两个关键类&#xff0c;用于处理字节流。它们的主要区别在于它们处理数据的方式。 InputStream: InputStream是用于读取字节流的抽象类。它是所有字节输入流类的父类。InputStream的子类可以从不同的数据源读取字节&…...

鸿蒙HarmonyOS学习手册_入门篇

鸿蒙HarmonyOS学习手册_入门篇 文章目录 鸿蒙HarmonyOS学习手册_入门篇入门快速入门开发准备基本概念UI框架应用模型工具准备 构建第一个ArkTS应用&#xff08;Stage模型&#xff09;-快速入门-入门创建ArkTS工程ArkTS工程目录结构&#xff08;Stage模型&#xff09;构建第一个…...

云计算——弹性云计算器(ECS)

弹性云服务器&#xff1a;ECS 概述 云计算重构了ICT系统&#xff0c;云计算平台厂商推出使得厂家能够主要关注应用管理而非平台管理的云平台&#xff0c;包含如下主要概念。 ECS&#xff08;Elastic Cloud Server&#xff09;&#xff1a;即弹性云服务器&#xff0c;是云计算…...

基于距离变化能量开销动态调整的WSN低功耗拓扑控制开销算法matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.算法仿真参数 5.算法理论概述 6.参考文献 7.完整程序 1.程序功能描述 通过动态调整节点通信的能量开销&#xff0c;平衡网络负载&#xff0c;延长WSN生命周期。具体通过建立基于距离的能量消耗模型&am…...

【第二十一章 SDIO接口(SDIO)】

第二十一章 SDIO接口 目录 第二十一章 SDIO接口(SDIO) 1 SDIO 主要功能 2 SDIO 总线拓扑 3 SDIO 功能描述 3.1 SDIO 适配器 3.2 SDIOAHB 接口 4 卡功能描述 4.1 卡识别模式 4.2 卡复位 4.3 操作电压范围确认 4.4 卡识别过程 4.5 写数据块 4.6 读数据块 4.7 数据流…...

微信小程序 - 手机震动

一、界面 <button type"primary" bindtap"shortVibrate">短震动</button> <button type"primary" bindtap"longVibrate">长震动</button> 二、js逻辑代码 注&#xff1a;文档 https://developers.weixin.qq…...

oracle与MySQL数据库之间数据同步的技术要点

Oracle与MySQL数据库之间的数据同步是一个涉及多个技术要点的复杂任务。由于Oracle和MySQL的架构差异&#xff0c;它们的数据同步要求既要保持数据的准确性和一致性&#xff0c;又要处理好性能问题。以下是一些主要的技术要点&#xff1a; 数据结构差异 数据类型差异&#xff…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序

一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...

BCS 2025|百度副总裁陈洋:智能体在安全领域的应用实践

6月5日&#xff0c;2025全球数字经济大会数字安全主论坛暨北京网络安全大会在国家会议中心隆重开幕。百度副总裁陈洋受邀出席&#xff0c;并作《智能体在安全领域的应用实践》主题演讲&#xff0c;分享了在智能体在安全领域的突破性实践。他指出&#xff0c;百度通过将安全能力…...

用docker来安装部署freeswitch记录

今天刚才测试一个callcenter的项目&#xff0c;所以尝试安装freeswitch 1、使用轩辕镜像 - 中国开发者首选的专业 Docker 镜像加速服务平台 编辑下面/etc/docker/daemon.json文件为 {"registry-mirrors": ["https://docker.xuanyuan.me"] }同时可以进入轩…...

在WSL2的Ubuntu镜像中安装Docker

Docker官网链接: https://docs.docker.com/engine/install/ubuntu/ 1、运行以下命令卸载所有冲突的软件包&#xff1a; for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done2、设置Docker…...

如何理解 IP 数据报中的 TTL?

目录 前言理解 前言 面试灵魂一问&#xff1a;说说对 IP 数据报中 TTL 的理解&#xff1f;我们都知道&#xff0c;IP 数据报由首部和数据两部分组成&#xff0c;首部又分为两部分&#xff1a;固定部分和可变部分&#xff0c;共占 20 字节&#xff0c;而即将讨论的 TTL 就位于首…...