Java 读取 sun 包的源码

Java 读取 sun 包的源码

研究 Jdk 的时候,在查看 sun 包下面的代码时,总是没有 source,于是下载了在 github 上下载了 openjdk 的源码,然后关联上 IDE,就可以看到其源码,下面分享出来

以 jdk8 的版本进行举例


下载 OpenJDK 的源码到本地

git clone https://gitclone.com/github.com/openjdk/jdk.git
cd jdk
git checkout jdk8-b120

或者之前 openjdk 维护的镜像其中有 jdk10 以及之前的 分支

git clone https://gitclone.com/github.com/openjdk-mirror/jdk.git
cd jdk
git checkout jdk8u/jdk8u/master

在 git 地址的前面加上 gitclone.com/ 可以加速


配置 IDE 环境

以 IDEA 进行举例,其源码放在文件的 /jdk/src/share/classes
环境配置

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Java进行网络抓的示例代码: ```java import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.SocketChannel; import java.util.Arrays; import java.util.Iterator; public class NetworkCapture { private Selector selector; public NetworkCapture() throws IOException { this.selector = Selector.open(); } public void capture(String hostname, int port) throws UnknownHostException, IOException { InetAddress address = InetAddress.getByName(hostname); SocketChannel channel = SocketChannel.open(); channel.configureBlocking(false); channel.connect(address, port); channel.register(selector, SelectionKey.OP_CONNECT); while (selector.select() > 0) { Iterator<SelectionKey> iterator = selector.selectedKeys().iterator(); while (iterator.hasNext()) { SelectionKey key = iterator.next(); iterator.remove(); if (key.isConnectable()) { SocketChannel sc = (SocketChannel) key.channel(); if (sc.finishConnect()) { key.interestOps(SelectionKey.OP_READ); } } else if (key.isReadable()) { SocketChannel sc = (SocketChannel) key.channel(); ByteBuffer buffer = ByteBuffer.allocate(1024); int bytesRead = sc.read(buffer); if (bytesRead == -1) { key.cancel(); sc.close(); break; } buffer.flip(); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); System.out.println(Arrays.toString(bytes)); } } } } public static void main(String[] args) throws UnknownHostException, IOException { NetworkCapture capture = new NetworkCapture(); capture.capture("www.google.com", 80); } } ``` 这个示例代码使用Java NIO实现了网络抓。它连接到指定的主机和端口,并读取所有传入的数据。在读取到数据时,它将字节数组打印到控制台上。你可以根据需要修改这个示例代码,以适应你的特定需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值