<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Tue, 10 Nov 2026 03:16:36 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>
	<item>
		<title>[原创] WordPress 插件Gutenberg升级卡死排查与修复全记录</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-wordpress-%e6%8f%92%e4%bb%b6gutenberg%e5%8d%87%e7%ba%a7%e5%8d%a1%e6%ad%bb%e6%8e%92%e6%9f%a5%e4%b8%8e%e4%bf%ae%e5%a4%8d%e5%85%a8%e8%ae%b0%e5%bd%95/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-wordpress-%e6%8f%92%e4%bb%b6gutenberg%e5%8d%87%e7%ba%a7%e5%8d%a1%e6%ad%bb%e6%8e%92%e6%9f%a5%e4%b8%8e%e4%bf%ae%e5%a4%8d%e5%85%a8%e8%ae%b0%e5%bd%95/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Tue, 10 Nov 2026 03:15:28 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Gutenberg]]></category>
		<category><![CDATA[PclZip]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[插件升级]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14297</guid>

					<description><![CDATA[<blockquote>
<p>
		场景：某 WordPress 站点的插件升级故障<br />
		说明：<code>/var/www/wordpress</code> 为示例路径。<br />
		结论：<strong>PHP 缺少 <code>zip</code> 扩展 &#8594; WordPress 回退到纯 PHP 的 PclZip 解压 &#8594; 解 48MB 的 Gutenberg 包时撞穿 256MB 内存上限 &#8594; PHP Fatal &#8594; 页面中断，表现为「无任何报错地卡死」</strong>。装 <code>php-pecl-zip</code> 后 1.7 秒完成，问题彻底消失。</p>
</blockquote>
<p><span id="more-14297"></span></p>
<h2>
	<span class="content">1、故障现象</span></h2>
<p>
	在 WordPress 后台升级 Gutenberg 插件，页面输出停在：</p>
<pre class="custom">
<code class="hljs">正开始升级。这个过程在某些服务器上花的时间要长些，请耐心等待。
正在升级 Gutenberg 插件（1 / 1）</code></pre>
<p>
	之后<strong>没有任何后续信息</strong>，不报错、不超时提示，插件也没有升级成功。可反复重现。</p>
<p>
	症状的迷惑性在于：WordPress 的批量升级是「一个请求跑完整个解压过程，成功了才输出结果」。中途 PHP Fatal 会导致 HTTP 响应被截断，浏览器只拿到半截页面，于是<strong>看起来像&#34;卡住&#34;，实际是进程已经死了</strong>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-wordpress-%e6%8f%92%e4%bb%b6gutenberg%e5%8d%87%e7%ba%a7%e5%8d%a1%e6%ad%bb%e6%8e%92%e6%9f%a5%e4%b8%8e%e4%bf%ae%e5%a4%8d%e5%85%a8%e8%ae%b0%e5%bd%95/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<blockquote>
<p>
		场景：某 WordPress 站点的插件升级故障<br />
		说明：<code>/var/www/wordpress</code> 为示例路径。<br />
		结论：<strong>PHP 缺少 <code>zip</code> 扩展 &rarr; WordPress 回退到纯 PHP 的 PclZip 解压 &rarr; 解 48MB 的 Gutenberg 包时撞穿 256MB 内存上限 &rarr; PHP Fatal &rarr; 页面中断，表现为「无任何报错地卡死」</strong>。装 <code>php-pecl-zip</code> 后 1.7 秒完成，问题彻底消失。</p>
</blockquote>
<p><span id="more-14297"></span></p>
<h2>
	<span class="content">1、故障现象</span></h2>
<p>
	在 WordPress 后台升级 Gutenberg 插件，页面输出停在：</p>
<pre class="custom">
<code class="hljs">正开始升级。这个过程在某些服务器上花的时间要长些，请耐心等待。
正在升级 Gutenberg 插件（1 / 1）</code></pre>
<p>
	之后<strong>没有任何后续信息</strong>，不报错、不超时提示，插件也没有升级成功。可反复重现。</p>
<p>
	症状的迷惑性在于：WordPress 的批量升级是「一个请求跑完整个解压过程，成功了才输出结果」。中途 PHP Fatal 会导致 HTTP 响应被截断，浏览器只拿到半截页面，于是<strong>看起来像&quot;卡住&quot;，实际是进程已经死了</strong>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h2>
	<span class="content">2、环境要点</span></h2>
<p>
	WordPress 跑在 nginx + PHP-FPM（unix socket）的标准部署下，站点根目录为 <code>/var/www/wordpress</code>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h2>
	<span class="content">3、排查路径</span></h2>
<h3>
	<span class="content">3.1 先排除&quot;资源不够&quot;这类常见原因</span></h3>
<table>
<thead>
<tr>
<th>
				怀疑项</th>
<th>
				实测结果</th>
<th>
				结论</th>
</tr>
</thead>
<tbody>
<tr>
<td>
				磁盘满</td>
<td>
				磁盘余量充足，inode 未逼近上限</td>
<td>
				排除</td>
</tr>
<tr>
<td>
				内存耗尽被 OOM</td>
<td>
				无 OOM 记录，仍有数百 MB 可用</td>
<td>
				排除</td>
</tr>
<tr>
<td>
				出口网络慢（下载插件包）</td>
<td>
				下载同一个包耗时正常（秒级）</td>
<td>
				排除</td>
</tr>
<tr>
<td>
				网关超时</td>
<td>
				错误日志无 504/499</td>
<td>
				排除</td>
</tr>
<tr>
<td>
				目录权限</td>
<td>
				站点文件属主与 PHP-FPM 运行用户一致</td>
<td>
				排除</td>
</tr>
<tr>
<td>
				升级临时目录残留</td>
<td>
				<code>wp-content/upgrade/</code> 只剩 <code>index.php</code>，无 <code>.maintenance</code></td>
<td>
				排除</td>
</tr>
</tbody>
</table>
<blockquote>
<p>
		网络那条特别值得先测：如果下载占了 5 分钟，会误以为是网络问题。这里 <code>curl -w &#39;%{time_total}&#39;</code> 一次就排除了。</p>
</blockquote>
<h3>
	<span class="content">3.2 定位到关键日志</span></h3>
<p>
	WordPress 的升级错误在 PHP 层，先看 php-fpm 的 <strong>PHP 错误日志</strong>（该日志路径由 pool 配置里的 <code>php_admin_value[error_log]</code> 指定）：</p>
<pre class="custom">
<code class="hljs">/var/log/php-fpm/www-error.log</code></pre>
<p>
	里面有一条，时间戳与操作时刻完全吻合（<code>02:00:07 UTC</code> = 北京时间 <code>10:00:07</code>）：</p>
<pre class="custom">
<code class="hljs">[10-Nov-2026 02:00:07 UTC] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted
(tried to allocate 2097152 bytes) in /var/www/wordpress/wp-admin/includes/class-pclzip.php on line 4250</code></pre>
<p>
	<strong>这一行就定性了</strong>：<code>268435456</code> = 256MB，<code>class-pclzip.php</code> = 纯 PHP 的 unzip 实现。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h3>
	<span class="content">3.3 出错代码</span></h3>
<pre class="custom">
<code class="hljs">// wp-admin/includes/class-pclzip.php 约 4249-4257 行
$v_data = @fread($this-&gt;zip_fd, $p_entry[&#39;compressed_size&#39;]);  // &larr; 4250 行，这里要 2MB 但内存已满
$p_string = @gzinflate($v_data);                               // 解压后的数据同样全在内存里</code></pre>
<p>
	PclZip 的工作方式是：把压缩包读进内存 &rarr; 逐条目 <code>gzinflate</code> &rarr; 结果继续留在内存 &rarr; 再写盘。<strong>内存峰值 &asymp; 压缩包大小 + 单条目解压后大小 + 各种副本</strong>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h3>
	<span class="content">3.4 三个数字凑齐了因果链</span></h3>
<table>
<thead>
<tr>
<th>
				事实</th>
<th>
				数值</th>
<th>
				怎么查的</th>
</tr>
</thead>
<tbody>
<tr>
<td>
				Gutenberg 压缩包大小</td>
<td>
				<strong>50,295,819 字节（48MB）</strong></td>
<td>
				<code>curl -O</code> 后 <code>ls -l</code></td>
</tr>
<tr>
<td>
				解压后插件目录</td>
<td>
				<strong>238MB</strong>（升级后 24.3.1 为 279MB）</td>
<td>
				<code>du -sh</code></td>
</tr>
<tr>
<td>
				PHP 内存上限</td>
<td>
				php.ini 写 <strong>128M</strong>，但 WP 后台会抬到 <strong>256M</strong></td>
<td>
				见下</td>
</tr>
</tbody>
</table>
<p>
	<strong>为什么是 256M 而不是 128M</strong>：<code>wp-admin/admin.php</code> 会调用 <code>wp_raise_memory_limit(&#39;admin&#39;)</code>，把上限提到 <code>WP_MAX_MEMORY_LIMIT</code>（默认 <code>&#39;256M&#39;</code>）。所以后台操作实际可用 256M。</p>
<p>
	<strong>为什么没走 ZipArchive</strong>：</p>
<pre class="custom">
<code class="hljs">$ rpm -qa | grep -i php | grep -i zip   # 包列表里没有 zip 扩展
$ php -r &#39;var_dump(class_exists(&quot;ZipArchive&quot;));&#39;
bool(false)</code></pre>
<p>
	WordPress 的 <code>unzip_file()</code> 优先用 <code>ZipArchive</code>（C 实现的 libzip），<strong>只有在 <code>ZipArchive</code> 不存在时才回退到 PclZip</strong>。这我的机器上恰好没装 <code>zip</code> 扩展，于是走了最耗内存的那条路。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h2>
	<span class="content">4、根本原因</span></h2>
<pre class="custom">
<code class="hljs">PHP 缺 zip 扩展（无 ZipArchive）
        &darr;
WordPress 回退到纯 PHP 的 PclZip 解压
        &darr;
Gutenberg 包 48MB，解压后 238MB，PclZip 全程在进程内存里堆
        &darr;
撞穿 256MB（WP_MAX_MEMORY_LIMIT 默认值）
        &darr;
PHP Fatal &rarr; 请求中断 &rarr; 浏览器只看到半截页面
        &darr;
表现为「升级卡死、没有任何错误信息」</code></pre>
<blockquote>
<p>
		注意区分这里的两个&quot;内存&quot;：爆掉的是 <strong>PHP 单进程的 <code>memory_limit</code></strong>，不是物理内存，所以<strong>加大 swap 或加大物理内存都救不了它</strong>。这也是后来没有去改 <code>wp-config.php</code> 里 <code>WP_MAX_MEMORY_LIMIT</code> 的原因&mdash;&mdash;治本要装扩展。</p>
</blockquote>
<h2>
	<span class="content">5、修复</span></h2>
<h3>
	<span class="content">5.1 安装 zip 扩展</span></h3>
<pre class="custom">
<code class="hljs">yum install -y php-pecl-zip</code></pre>
<p>
	注意事项：</p>
<ul>
<li>
		包名要与<strong>当前 PHP 版本</strong>匹配（常见形式为 <code>php-pecl-zip</code> 或 <code>php&lt;版本&gt;-php-pecl-zip</code>），版本号段不匹配则不会生效。</li>
<li>
		该扩展一般在发行版自带的 PHP 扩展仓库里就能装到，<strong>安装它不会改变 PHP 本体版本</strong>。</li>
</ul>
<p>
	安装后自动生成：</p>
<pre class="custom">
<code class="hljs">&lt;PHP 扩展目录&gt;/zip.so
&lt;PHP 配置目录&gt;/xx-zip.ini</code></pre>
<h3>
	<span class="content">5.2 重启 PHP-FPM</span></h3>
<pre class="custom">
<code class="hljs">systemctl restart php-fpm.service</code></pre>
<h3>
	<span class="content">5.3 验证扩展真的进了 FPM 进程</span></h3>
<p>
	CLI 能加载不等于 FPM 能加载，必须验证进程内实际映射了 <code>zip.so</code>：</p>
<pre class="custom">
<code class="hljs">MASTER=$(pgrep -f &#39;php-fpm: master process&#39; | head -1)
grep &#39;php/modules/zip.so&#39; /proc/$MASTER/maps
# 7f7ba4d8b000-... r-xp ... &lt;PHP 扩展目录&gt;/zip.so</code></pre>
<p>
	master 和 worker 都能看到，说明新 fork 的 worker 必然带 <code>ZipArchive</code>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h2>
	<span class="content">6、验证</span></h2>
<h3>
	<span class="content">6.1 隔离实测</span></h3>
<p>
	在 <code>/tmp</code> 里用<strong>完全相同的 256M 上限</strong>解同一个包：</p>
<pre class="custom">
<code class="hljs">cd /tmp &amp;&amp; curl -O https://downloads.wordpress.org/plugin/gutenberg.24.2.0.zip
php -d memory_limit=256M -r &#39;
  $z = new ZipArchive;
  $z-&gt;open(&quot;/tmp/gutenberg.24.2.0.zip&quot;);
  echo &quot;entries=&quot; . $z-&gt;numFiles . &quot;\n&quot;;
  echo &quot;extract=&quot; . ($z-&gt;extractTo(&quot;/tmp/gz-test&quot;) ? &quot;OK&quot; : &quot;FAIL&quot;) . &quot;\n&quot;;
  $z-&gt;close();
  echo &quot;php_peak=&quot; . round(memory_get_peak_usage(true)/1048576,1) . &quot;MB\n&quot;;
&#39;</code></pre>
<p>
	结果：</p>
<pre class="custom">
<code class="hljs">entries=2555
extract=OK
php_peak=2MB
real 1.661s</code></pre>
<p>
	对照实验在同一份插件包上进行，并将 PHP 内存上限同样设为 256MB。改造前，解压过程因内存耗尽而中断；改造后，解压于 1.66 秒内完成，PHP 进程的内存峰值仅为 2MB，二者相差约两个数量级。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h3>
	<span class="content">6.2 实际升级操作验证结果</span></h3>
<p>
	后台重新升级，Gutenberg <strong>24.2.0 &rarr; 24.3.1</strong> 成功。日志侧证据：</p>
<p>
	<strong>php-fpm 错误日志零新增</strong></p>
<pre class="custom">
<code class="hljs">grep -c &#39;Allowed memory size&#39;      &rarr; 1   （仍是 10:00 那次旧的）
grep -c &#39;Maximum execution time&#39;   &rarr; 0</code></pre>
<p>
	<strong>nginx 访问日志时间线</strong></p>
<pre class="custom">
<code class="hljs">10:10:40  POST /wp-admin/update-core.php?action=do-plugin-upgrade   200  42699B
10:10:41  GET  /wp-content/plugins/...?ver=1794276640               200        &larr; 页面已重载
10:10:47  GET  /wp-admin/update.php?action=update-selected&amp;plugins=gutenberg%2Fgutenberg.php  200</code></pre>
<p>
	从提交到页面刷新 <strong>1~3 秒</strong>（原先卡 5 分钟后静默失败）。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h2>
	<span class="content">7、一句话总结</span></h2>
<p>
	WordPress 后台「升级卡住、没有任何报错」这类问题，<strong>先去看 php-fpm 的 <code>www-error.log</code></strong>，一行 <code>Allowed memory size ... class-pclzip.php</code> 就能定性：服务器缺 <code>php-zip</code> 扩展，<code>yum install php-pecl-zip</code> + 重启 FPM 即可。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span> 版权声明 <span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p>
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-wordpress-%e6%8f%92%e4%bb%b6gutenberg%e5%8d%87%e7%ba%a7%e5%8d%a1%e6%ad%bb%e6%8e%92%e6%9f%a5%e4%b8%8e%e4%bf%ae%e5%a4%8d%e5%85%a8%e8%ae%b0%e5%bd%95/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 在 Ubuntu 上更新「极点五笔」词库（fcitx4 码表）</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8-ubuntu-%e4%b8%8a%e6%9b%b4%e6%96%b0%e3%80%8c%e6%9e%81%e7%82%b9%e4%ba%94%e7%ac%94%e3%80%8d%e8%af%8d%e5%ba%93%ef%bc%88fcitx4-%e7%a0%81%e8%a1%a8%ef%bc%89/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8-ubuntu-%e4%b8%8a%e6%9b%b4%e6%96%b0%e3%80%8c%e6%9e%81%e7%82%b9%e4%ba%94%e7%ac%94%e3%80%8d%e8%af%8d%e5%ba%93%ef%bc%88fcitx4-%e7%a0%81%e8%a1%a8%ef%bc%89/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Fri, 06 Nov 2026 12:38:49 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[fcitx4]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[更新词库]]></category>
		<category><![CDATA[极点五笔]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14278</guid>

					<description><![CDATA[<section data-tool="markdown2wechat编辑器" data-website="https://aizhuanqian.com" id="nice" style="font-size: 16px; padding: 0px 10px; line-height: 1.6; letter-spacing: 0px; word-break: break-word; overflow-wrap: break-word; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">现在使用五笔输入法的人是越来越少了，像我一样在Linux系统上使用五笔的，就更是少得可怜。想当年，五笔输入法还是一个比较流行的输入法的时候，在Windows上有一个非常火爆的软件：极点五笔输入法。后来有人把它移植到了Linux系统，但这种没有大公司支持的项目，是没有持续更新支持的，所以，这么多年来，我一直使用着一个过时的词库，如果遇到词库里没有的专用词，我就自己用快捷键把它加到词库里，多年累积下来，也算是更新了一小部分词库。但实际上，还是有很多覆盖不到的词，比如原始词库连&#34;支付宝&#34;都不认识。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">为了解决这个问题，我在AI的辅助下做了一些调研，并在此基础上对Ubuntu上使用的极点五笔输入法词库做了一次与时俱进的更新。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">说得简单点，就是如下这个过程：从公网找词库 &#8594; 筛选 &#8594; 转成 fcitx4 二进制码表 &#8594; 校验 &#8594; 上线 &#8594; 回滚预案。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">配套代码已开源：<a href="https://github.com/codelast/update-freewb-dict-on-linux" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);" target="_blank">LINK</a></strong></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">文中只展示核心代码片段；<strong style="font-weight: bold; color: black;">片段为示意节选，与仓库里的文件不完全逐行一致，请以仓库中的实际代码为准</strong>（每节标注了文件名并附链接）。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">以下所有命令都假设你已克隆并进入仓库目录：</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">git clone https://github.com/codelast/update-freewb-dict-on-linux.git &#38;&#38; cd update-freewb-dict-on-linux</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">适用：fcitx 4.x + <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">fcitx-table-wbpy</code>（「五笔拼音」，词库源自极点五笔的极爽词库）。</section>
</li>
</ul>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span id="more-14278"></span><br />
	0. 速览</span></h2>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				环节</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				要点</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				我的Ubuntu机器在用的东西</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Linux 上没有 Windows 版极点五笔；实际是 <strong style="font-weight: bold;">fcitx4 的 table 引擎 + wbpy 码表</strong>，词库是「极爽词库 6.0」</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				词库文件</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>~/.config/fcitx/table/wbpy.mb</code></td></tr></tbody></table></section>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8-ubuntu-%e4%b8%8a%e6%9b%b4%e6%96%b0%e3%80%8c%e6%9e%81%e7%82%b9%e4%ba%94%e7%ac%94%e3%80%8d%e8%af%8d%e5%ba%93%ef%bc%88fcitx4-%e7%a0%81%e8%a1%a8%ef%bc%89/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<section data-tool="markdown2wechat编辑器" data-website="https://aizhuanqian.com" id="nice" style="font-size: 16px; padding: 0px 10px; line-height: 1.6; letter-spacing: 0px; word-break: break-word; overflow-wrap: break-word; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;">
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">现在使用五笔输入法的人是越来越少了，像我一样在Linux系统上使用五笔的，就更是少得可怜。想当年，五笔输入法还是一个比较流行的输入法的时候，在Windows上有一个非常火爆的软件：极点五笔输入法。后来有人把它移植到了Linux系统，但这种没有大公司支持的项目，是没有持续更新支持的，所以，这么多年来，我一直使用着一个过时的词库，如果遇到词库里没有的专用词，我就自己用快捷键把它加到词库里，多年累积下来，也算是更新了一小部分词库。但实际上，还是有很多覆盖不到的词，比如原始词库连&quot;支付宝&quot;都不认识。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">为了解决这个问题，我在AI的辅助下做了一些调研，并在此基础上对Ubuntu上使用的极点五笔输入法词库做了一次与时俱进的更新。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">说得简单点，就是如下这个过程：从公网找词库 &rarr; 筛选 &rarr; 转成 fcitx4 二进制码表 &rarr; 校验 &rarr; 上线 &rarr; 回滚预案。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">配套代码已开源：<a href="https://github.com/codelast/update-freewb-dict-on-linux" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);" target="_blank">LINK</a></strong></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">文中只展示核心代码片段；<strong style="font-weight: bold; color: black;">片段为示意节选，与仓库里的文件不完全逐行一致，请以仓库中的实际代码为准</strong>（每节标注了文件名并附链接）。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">以下所有命令都假设你已克隆并进入仓库目录：</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">git clone https://github.com/codelast/update-freewb-dict-on-linux.git &amp;&amp; cd update-freewb-dict-on-linux</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">适用：fcitx 4.x + <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">fcitx-table-wbpy</code>（「五笔拼音」，词库源自极点五笔的极爽词库）。</section>
</li>
</ul>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span id="more-14278"></span><br />
	0. 速览</span></h2>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				环节</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				要点</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				我的Ubuntu机器在用的东西</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Linux 上没有 Windows 版极点五笔；实际是 <strong style="font-weight: bold;">fcitx4 的 table 引擎 + wbpy 码表</strong>，词库是「极爽词库 6.0」</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				词库文件</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>~/.config/fcitx/table/wbpy.mb</code>（二进制，约 10MB，30 万条量级）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				能不能直接编辑</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">不能</strong>。私有二进制格式，必须解析&rarr;改&rarr;重新序列化</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				权威格式来源</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				fcitx4 源码 <code>src/im/table/tabledict.c</code>、<code>tools/cli/mb2txt.c</code>、<code>tools/cli/txt2mb.c</code></td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				关键工具</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				用 <code>build_mb2txt.sh</code> 编译<strong style="font-weight: bold;">官方</strong> <code>mb2txt</code> 做回读校验</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				上线流程</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				停 fcitx &rarr; 备份 &rarr; 基于最新文件重建 &rarr; 官方工具全量 diff &rarr; 替换 &rarr; 启动 &rarr; 实打验证</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				回滚</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>./rollback.sh &lt;备份&gt;</code>，一分钟</td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	本次实际成果（示例）：词库 312,315 &rarr; 336,897 条，新增五笔 10,203 条、拼音 14,378 条，原有记录零丢失。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content"><span style="font-size: 16px; color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" style="font-size: 16px;" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	仓库文件清单</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	下表文件均位于仓库 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">main</code> 分支，点击文件名可直达源码。</p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				文件</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				作用</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				依赖</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/build_mb2txt.sh" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>build_mb2txt.sh</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				编译官方 <code>mb2txt</code>（码表 &rarr; 文本）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				gcc、curl</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/tabledict.h" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>tabledict.h</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				编译用的极简头文件</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				&mdash;</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/stub.c" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>stub.c</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>fcitx_utils_read_uint32</code> 的替代实现</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				&mdash;</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/mb_table.py" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>mb_table.py</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">码表读写库</strong>（解析 / 序列化 / 有序插入）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				仅标准库</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/merge_wubi.py" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>merge_wubi.py</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				并入五笔词条（type=0）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				mb_table.py</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/gen_pinyin.py" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>gen_pinyin.py</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				生成拼音码（含多音备选）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				pypinyin</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/merge_pinyin.py" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>merge_pinyin.py</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				并入拼音记录（type=1）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				mb_table.py</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/filter_candidates.py" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>filter_candidates.py</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				候选筛选（差集 + 质量判据）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				词库文件、字频表</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/apply.sh" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>apply.sh</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				停服&rarr;备份&rarr;校验&rarr;替换&rarr;重启</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				mb2txt</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/rollback.sh" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code>rollback.sh</code></a></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				回滚到备份</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				&mdash;</td>
</tr>
</tbody>
</table>
</section>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">1. 背景与原理</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">1.1 「极点五笔」在 Linux 上到底是什么</span></h3>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				平台</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				实现</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				词库载体</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Windows</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				极点五笔（FreeWB，杜志民）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>freeime\mb\</code> 下的纯文本码表目录</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Ubuntu（本文）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				fcitx4 的 table 引擎 + 码表 <code>wbpy</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>~/.config/fcitx/table/wbpy.mb</code>（二进制）</td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	所以「更新极点五笔词库」在 Linux 上等于「替换 wbpy.mb 里的词条数据」。<strong style="font-weight: bold;">引擎、快捷键、皮肤、用户造词习惯全部不变</strong>，只是数据变了。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">wbpy.conf</code> 里几个决定格式的关键参数：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">[CodeTable]
UniqueName=wbpy
Name[zh_CN]=五笔拼音
File=wbpy.mb
ExactMatch=False     ; 前缀匹配 &rarr; 拼音码被截断也照样能用
UsePY=False
PYKey=z
</code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">1.2 为什么不直接用文本编辑器</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">.mb</code> 是 fcitx 私有的二进制表：头部含按键字符集、码长、组词规则，记录区是按码排序的定长头 + 变长词条。 用文本工具改，轻则加载失败，重则索引错乱（能启动但查不到词）。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span style="font-size: 16px; color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" style="font-size: 16px;" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	2. 二进制格式（权威来源 + 实测）</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">2.1 源码位置</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	GitHub <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">fcitx/fcitx</code>（fcitx4，已归档）：</p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				文件</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				作用</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>src/im/table/tabledict.c</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>TableData::load/save</code>，<strong style="font-weight: bold;">格式的唯一权威</strong></td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>tools/cli/mb2txt.c</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				官方 二进制 &rarr; 文本</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>tools/cli/txt2mb.c</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				官方 文本 &rarr; 二进制</td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26a0.png" alt="⚠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 不要参考 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">nopdan/rose</code> 的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">format/fcitx4_mb</code>：它假设码字段宽度 = <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">codeLen + 1</code>（=5），实际是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">pyCodeLen + 1</code>（本文示例 = 13）。按它的写法解析会整体错位一条记录。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">2.2 文件结构</span></h3>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">┌── 头部 ─────────────────────────────────────────────┐
│ u32  0                    新格式标志                  │
│ i8   version              3 = 当前版本（&lt;3 为旧版）   │
│ u32  keyLen                                          │
│ u8   KeyCode[keyLen+1]    NUL 结尾，如 <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;abc...y&quot;</span>      │
│ u8   codeLen              码长（本文示例 4）          │
│ u8   pyCodeLen            拼音码长（本文示例 12）     │
│ u32  ignoreLen                                       │
│ u8   InvalidChar[ignoreLen+1]                        │
│ u8   hasRule             1 = 后面跟组词规则表         │
│ (codeLen-1) &times; [ u8 flag, u8 words,                   │
│                 codeLen &times; (u8 flag, u8 <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">which</span>, u8 idx) ]│
│ u32  recordCount                                     │
├── 记录区（按码排序，共 recordCount 条）──────────────┤
│ 每条：                                               │
│   码    pyCodeLen+1 字节（NUL 填充；本文 13 字节）    │
│   u32   词长（**含**结尾 NUL）                        │
│   词    UTF-8 字节 + NUL                             │
│   i8    <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">type</span>  0=五笔 1=拼音 2=自造词 3=提示           │
│   u32   iHit  用户命中次数（新词写 0）                │
│   u32   iIndex 全局递增序号（新词取 max+1）           │
└─────────────────────────────────────────────────────┘
</code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">2.3 三条硬约束（踩过才知道）</span></h3>
<ol data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">记录必须按「码的首字符」分组排序</strong>。<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">table.c</code>（上游源码，仅阅读参考） 建索引时只比较 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">cChar != strCode[0]</code>，顺序乱了就查不到。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">同码候选的先后 = 记录在文件里的先后</strong>。想让它排最后，就插到该码组的<strong style="font-weight: bold; color: black;">末尾</strong>；想排第一，插到组首。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">前 4 字节不是词长</strong>，而是码字段的第 5~8 字节。这是最容易搞错的地方（第一版解析器就栽在这）。</section>
</li>
</ol>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">2.4 匹配行为（决定拼音码能不能截断）</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">tabledict.c::TableCompareCode()</code> 只按<strong style="font-weight: bold;">用户输入长度</strong>逐字节比较，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">wbpy.conf</code> 里 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ExactMatch=False</code>，所以是<strong style="font-weight: bold;">前缀匹配</strong>：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;"><span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">size_t</span> tmp_len = <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">strlen</span>(strUser);
<span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> (i = <span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>; i &lt; tmp_len; i++) { <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> (strUser[i] != strDict[i]) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> &hellip;; }
<span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> (exactMatch &amp;&amp; <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">strlen</span>(strUser) != <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">strlen</span>(strDict)) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-number" style="color: #986801; line-height: 26px;">-999</span>;
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	含义：拼音码被截断到 12 字母也照样能用（打前几个字母就出候选）；五笔 4 码同理。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span style="font-size: 16px; color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" style="font-size: 16px;" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	3. 工具链：编译官方 mb2txt</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">文件：<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/build_mb2txt.sh" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code style="font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; background-color: rgba(27, 31, 35, 0.05); font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; word-break: break-all;">build_mb2txt.sh</code></a></strong>（配合 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/tabledict.h" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code style="font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; background-color: rgba(27, 31, 35, 0.05); font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; word-break: break-all;">tabledict.h</code></a>、<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/stub.c" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code style="font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; background-color: rgba(27, 31, 35, 0.05); font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; word-break: break-all;">stub.c</code></a>）</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">mb2txt.c</code>（脚本自动下载） 只外部依赖一个 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">fcitx_utils_read_uint32</code>，所以可以脱离 fcitx 开发环境单独编译。脚本做的事就是：放好极简头文件 &rarr; 下载官方 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">mb2txt.c</code> &rarr; 用 stub 编译。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	核心三行：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">mkdir -p im/table &amp;&amp; cp -f tabledict.h im/table/tabledict.h
curl -fsSL -o mb2txt.c https://raw.githubusercontent.com/fcitx/fcitx/master/tools/cli/mb2txt.c
gcc -O2 -I. -o mb2txt mb2txt.c stub.c
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	产出用法：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">./mb2txt        ~/.config/fcitx/table/wbpy.mb &gt; table.txt   <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 二进制 &rarr; 文本</span>
./mb2txt -o 旧版.mb &gt; old.txt                               <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 旧格式（version&lt;3）</span>
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	输出形如：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">;fcitx Version 0x03 Table file
KeyCode=abcdefghijklmnopqrstuvwxy
Length=4
Pinyin=@
PinyinLength=12
Prompt=&amp;
ConstructPhrase=^
[Rule]
e2=p11+p12+p21+p22
e3=p11+p21+p31+p32
a4=p11+p21+p31+n11
[Data]
a 工
a 戈
@a 阿          &larr; @ 开头 = <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">type</span>=1（拼音记录）
</code></pre>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span style="font-size: 16px; color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" style="font-size: 16px;" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	4. 从公网找词库 + 筛选</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">文件：<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/filter_candidates.py" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code style="font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; background-color: rgba(27, 31, 35, 0.05); font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; word-break: break-all;">filter_candidates.py</code></a></strong></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">4.1 数据源（全部开源可下载）</span></h3>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				来源</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				地址（标识）</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				内容</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				备注</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				白霜五笔</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GitHub <code>gaboolic/rime-frost</code> &rarr; <code>cn_dicts_wb/{chars,words}.dict.yaml</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				词 + 五笔码 + 现代语料词频</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				词频用 7 亿字语料重算（GPL-3.0）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				墨奇五笔</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GitHub <code>gaboolic/rime-wubi-sentence</code> &rarr; <code>cn_dicts_wb/base.dict.yaml</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				36 万条，含大量新词/专名</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				码字段是&quot;整句码&quot;，需要还原（MIT）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				现代汉语常用词表</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				gist <code>indiejoseph/eae09c673460aa0b56db</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				5.6 万条规范词表</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				判定&quot;是不是一个词&quot;（无显式许可，仅作判据）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				成语库</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GitHub <code>pwxcoo/chinese-xinhua</code> &rarr; <code>data/idiom.json</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				3.09 万条成语</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				4 字词精确筛选（MIT）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				本机表</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				自己 <code>mb2txt</code> 出来的 dump</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				已有词、单字五笔全码、单字读音</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				差集 + 编码校验基准</td>
</tr>
</tbody>
</table>
</section>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">4.2 两个词库的码字段怎么还原</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	白霜：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">词 \t 4字母码 \t 词频</code>，直接用。 墨奇：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">词 \t &quot;xx,ax xx,ax &hellip;&quot; \t 权重</code>，每段对应一个字、逗号前是该字前两码，按五笔词组规则还原：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;"><span class="hljs-function" style="line-height: 26px;"><span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">def</span> <span class="hljs-title" style="color: #4078f2; line-height: 26px;">moqi_to_code</span><span class="hljs-params" style="line-height: 26px;">(s)</span>:</span>
    segs = [x.split(<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;,&#39;</span>)[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> x <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> s.split()]
    n = len(segs)
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> n == <span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>:  <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>][:<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>] + segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>][:<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>]
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> n == <span class="hljs-number" style="color: #986801; line-height: 26px;">3</span>:  <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>][:<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>]
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + segs[<span class="hljs-number" style="color: #986801; line-height: 26px;">-1</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>]
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	（2 字=各前两码；3 字=首字首码+次字首码+末字前两码；4 字以上=前三字首码+末字首码）</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">4.3 质量判据：用「凝固度」把搭配垃圾挡在门外</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	拼音词库是给<strong style="font-weight: bold;">整句解码</strong>用的，天然塞满 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">有多</code>、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">人是</code>、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">的时候</code> 这类高频二元组。它们对拼音输入有意义，对五笔是纯噪音。</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">PMI（内部凝固度）</strong>：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">PMI = log2( P(w) / &Pi; P(c) )</code>，再除以 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">(词长-1)</code> 做长度归一。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">阈值怎么定</strong>：拿&quot;本机已收录的 2 字词&quot;反推分布&mdash;&mdash;实测 P25 &asymp; 5.0、中位数 &asymp; 8.0 &rarr; 取 <strong style="font-weight: bold; color: black;">归一化 PMI &ge; 5.0</strong>。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">对照：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">人是</code> -2.5、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">中有</code> -0.9、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">是最</code> -0.2、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">有多</code> 1.7（都在底部分位）；<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">题主</code> 11.5、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">刷题</code> 8.2、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">算力</code> 6.8。</section>
</li>
</ul>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	PMI 不是充分条件（<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">的时候</code> PMI 18.1 也不是词），所以再叠三层：<strong style="font-weight: bold;">虚词字过滤 &rarr; 方位/副词短语过滤 &rarr; 词典交叉</strong>（把&quot;确认是词&quot;和&quot;疑似新词&quot;分成两档）。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	核心片段（<a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/filter_candidates.py" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code style="font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; background-color: rgba(27, 31, 35, 0.05); font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; word-break: break-all;">filter_candidates.py</code></a>）：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;"><span class="hljs-function" style="line-height: 26px;"><span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">def</span> <span class="hljs-title" style="color: #4078f2; line-height: 26px;">word_code</span><span class="hljs-params" style="line-height: 26px;">(w)</span>:</span>
    <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;&quot;&quot;用本机单字全码拼词码（比信外部词库更一致）&quot;&quot;&quot;</span>
    cs = [wubi_single.get(ch) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> ch <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> w]
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> any(<span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">not</span> c <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> c <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> cs): <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">None</span>
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> len(w) == <span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>:   r = cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>][:<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>] + cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>][:<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>]
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">elif</span> len(w) == <span class="hljs-number" style="color: #986801; line-height: 26px;">3</span>: r = cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>][:<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>]
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">else</span>:             r = cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">2</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] + cs[<span class="hljs-number" style="color: #986801; line-height: 26px;">-1</span>][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>]
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> r <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> len(r) == <span class="hljs-number" style="color: #986801; line-height: 26px;">4</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> r.isalpha() <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">else</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">None</span>

<span class="hljs-function" style="line-height: 26px;"><span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">def</span> <span class="hljs-title" style="color: #4078f2; line-height: 26px;">pmi</span><span class="hljs-params" style="line-height: 26px;">(word, freq, tot_w)</span>:</span>
    pc = <span class="hljs-number" style="color: #986801; line-height: 26px;">1.0</span>
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> ch <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> word:
        <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> ch <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> char: <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">None</span>
        pc *= char[ch] / tot_c
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> math.log2((freq / tot_w) / pc) / max(<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>, len(word) - <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>)

<span class="hljs-function" style="line-height: 26px;"><span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">def</span> <span class="hljs-title" style="color: #4078f2; line-height: 26px;">keep</span><span class="hljs-params" style="line-height: 26px;">(w)</span>:</span>
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> set(w) &amp; FUNC: <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">False</span>                      <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 含虚词字</span>
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> len(w) &gt;= <span class="hljs-number" style="color: #986801; line-height: 26px;">3</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> w[<span class="hljs-number" style="color: #986801; line-height: 26px;">-1</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> LOC: <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">False</span>        <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 方位短语</span>
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> len(w) &gt;= <span class="hljs-number" style="color: #986801; line-height: 26px;">3</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> w[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> DEG: <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">False</span>         <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 副词开头</span>
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> any(g <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> w <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> g <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> GLUE): <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">False</span>           <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 常见口语搭配</span>
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> <span class="hljs-literal" style="color: #0184bb; line-height: 26px;">True</span>
</code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">4.4 三次实际筛选结果（示例）</span></h3>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				批次</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				范围</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				主要过滤</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; background-color: rgb(240, 240, 240); min-width: 85px; text-align: right;">
				阈值</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; background-color: rgb(240, 240, 240); min-width: 85px; text-align: right;">
				产出</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				A 常用词</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				2~3 字，本机缺失，且<strong style="font-weight: bold;">在现汉词表里</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				虚词字 + PMI&ge;5</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px; text-align: right;">
				&mdash;</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px; text-align: right;">
				1,163</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				B 新词/专名</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				2~3 字，本机缺失，<strong style="font-weight: bold;">不在</strong>词表</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				上述三层 + 搭配黑名单</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px; text-align: right;">
				词频&ge;500</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px; text-align: right;">
				2,302</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				C 成语</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				4 字，本机缺失，<strong style="font-weight: bold;">在成语库里</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				精确匹配成语库</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px; text-align: right;">
				全量</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px; text-align: right;">
				6,738</td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	经验：2 字档噪音约 15%，3 字档约 25~30%，4 字档原始候选噪音六成（必须靠成语库/词表分档）。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span style="font-size: 16px; color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" style="font-size: 16px;" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	5. 程序清单与核心逻辑</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.1 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/mb_table.py" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code>mb_table.py</code></a> &mdash; 码表读写库（核心）</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	对外三个函数：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">read(path) -&gt; Table</code>、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">write(path, table)</code>、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">insert_sorted(table, items)</code>。</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">read</code>：按 2.2 的结构解析，最后断言 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">len(records) == recordCount</code>（防格式判断失误）</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">write</code>：头部原样写回 + 记录逐条序列化（码左对齐 NUL 填充、词长含 NUL）</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">insert_sorted</code>：按码插入，<strong style="font-weight: bold; color: black;">同码插在组尾</strong>，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">iIndex</code> 取全局 max 递增</section>
</li>
</ul>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">insert_sorted</code> 的核心（候选顺序 = 文件顺序，所以插入位置决定排第几）：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;"><span class="hljs-function" style="line-height: 26px;"><span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">def</span> <span class="hljs-title" style="color: #4078f2; line-height: 26px;">insert_sorted</span><span class="hljs-params" style="line-height: 26px;">(table, new_items)</span>:</span>
    max_idx = max((r[<span class="hljs-number" style="color: #986801; line-height: 26px;">4</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> r <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> table.records), default=<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>)
    add = []
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> code, word, typ <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> new_items:
        max_idx += <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>
        add.append([code, word + <span class="hljs-string" style="color: #50a14f; line-height: 26px;">b&#39;\x00&#39;</span>, typ, <span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>, max_idx])
    add.sort(key=<span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">lambda</span> r: (r[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>], r[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>]))

    out, i, ai, recs = [], <span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>, <span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>, table.records
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">while</span> i &lt; len(recs):
        <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> ai &lt; len(add) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> add[ai][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] &lt; recs[i][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>]:
            out.append(add[ai]); ai += <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>
        <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">else</span>:
            cur = recs[i]; out.append(cur); i += <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>
            <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> ai &lt; len(add) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> add[ai][<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>] == cur[<span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>]:   <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 走到该码组末尾</span>
                out.append(add[ai]); ai += <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>
    out.extend(add[ai:])
    table.records = out
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">return</span> len(add)
</code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.2 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/merge_wubi.py" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code>merge_wubi.py</code></a> &mdash; 并入五笔词条</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	读 CSV（至少含 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">词,五笔码</code>），跳过表里已存在的词，调用 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">insert_sorted(..., type=0)</code>。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">have = {r[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>].rstrip(<span class="hljs-string" style="color: #50a14f; line-height: 26px;">b&#39;\x00&#39;</span>).decode(<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;utf-8&#39;</span>, <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;ignore&#39;</span>) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> r <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> t.records}
items = [(row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;五笔码&#39;</span>].encode(), row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;词&#39;</span>].encode(), <span class="hljs-number" style="color: #986801; line-height: 26px;">0</span>)
         <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> row <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> csv.DictReader(open(cand_csv, encoding=<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;utf-8&#39;</span>))
         <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;词&#39;</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> have]
n = mb_table.insert_sorted(t, items)
mb_table.write(dst, t)
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	用法：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">python3 merge_wubi.py &lt;源.mb&gt; &lt;候选.csv&gt; &lt;输出.mb&gt;</code></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.3 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/gen_pinyin.py" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code>gen_pinyin.py</code></a> &mdash; 生成拼音码（含多音字）</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	三个要点：词组级注音（避免多音字按单字乱读）、多音备选、按 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">pyCodeLen</code> 截断。 <strong style="font-weight: bold;">关键设计：备选读音必须在&quot;本机表里已出现过的单字读音&quot;白名单内</strong>，否则会造出输入法根本打不出的废码。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;"><span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 1) 从 dump 里取单字读音白名单</span>
local = collections.defaultdict(set)
<span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> ln <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> body:
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> ln.startswith(<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;@&#39;</span>) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39; &#39;</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> ln:
        c, w = ln[<span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>:].split(<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39; &#39;</span>, <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>)
        <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> len(w) == <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>:
            local[w].add(c)

<span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 2) 词组级注音 + 按白名单过滤每个字的读音</span>
base = <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;&#39;</span>.join(lazy_pinyin(w))[:<span class="hljs-number" style="color: #986801; line-height: 26px;">12</span>]
vs = pinyin(w, heteronym=<span class="hljs-literal" style="color: #0184bb; line-height: 26px;">True</span>, style=Style.NORMAL)
vs = [[p <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> p <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> lst <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> p <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> local.get(ch, {p})] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">or</span> lst <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> lst, ch <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> zip(vs, w)]

<span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 3) 组合候选，去重，最多保留 cap 个</span>
<span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> combo <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> itertools.product(*vs):
    p = <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;&#39;</span>.join(combo)[:<span class="hljs-number" style="color: #986801; line-height: 26px;">12</span>]
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> p <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> cands: cands.append(p)
    <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> len(cands) &gt;= cap: <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">break</span>
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	用法：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">python3 gen_pinyin.py &lt;词表.csv&gt; &lt;输出.csv&gt; &lt;表dump.txt&gt; [每词最多几个码]</code></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.4 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/merge_pinyin.py" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code>merge_pinyin.py</code></a> &mdash; 并入拼音记录</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	与 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">merge_wubi.py</code> 同构，区别是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">type=1</code>，且<strong style="font-weight: bold;">支持跳过冲突码</strong>：</p>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		若某拼音码恰好等于一个&quot;只有唯一候选&quot;的五笔码，插入后会破坏&quot;唯一即上屏&quot;。这类码要放进跳过列表。</p>
</blockquote>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">skip = set((sys.argv[<span class="hljs-number" style="color: #986801; line-height: 26px;">4</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> len(sys.argv) &gt; <span class="hljs-number" style="color: #986801; line-height: 26px;">4</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">else</span> <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;&#39;</span>).split(<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;,&#39;</span>))
items = [(row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;拼音码&#39;</span>].encode(), row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;词&#39;</span>].encode(), <span class="hljs-number" style="color: #986801; line-height: 26px;">1</span>)
         <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">for</span> row <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> csv.DictReader(open(py_csv, encoding=<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;utf-8&#39;</span>))
         <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">if</span> row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;拼音码&#39;</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;拼音码&#39;</span>] <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> skip
         <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">and</span> (row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;词&#39;</span>].encode(), row[<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;拼音码&#39;</span>].encode()) <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #a626a4; line-height: 26px;">in</span> existing]
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	用法：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">python3 merge_pinyin.py &lt;源.mb&gt; &lt;拼音.csv&gt; &lt;输出.mb&gt; [跳过的码,...]</code></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.5 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/filter_candidates.py" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code>filter_candidates.py</code></a> &mdash; 候选筛选</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	输入：本机 dump + 字频表（<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">chars.dict.yaml</code>）+ 一个或多个外部词库文件；输出 CSV：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">词,五笔码,词频,归一PMI</code>。 判据见第 4.3 节。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	用法：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">python3 filter_candidates.py &lt;dump.txt&gt; &lt;chars.dict.yaml&gt; &lt;词库1&gt; [词库2 ...] &gt; cand.csv</code></p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span style="font-size: 16px; color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" style="font-size: 16px;" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	6. 安装与验证</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">6.1 为什么必须先停 fcitx</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	fcitx-table 在<strong style="font-weight: bold;">退出时会重写整个 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">.mb</code></strong>（把内存里的表 + 用户造词落盘）。只要 fcitx 还在跑，你替换的文件可能被覆盖，或它下次退出时把内存旧表写回去。 所以顺序必须是：<strong style="font-weight: bold;">停 &rarr; 备份 &rarr; 基于最新文件重建 &rarr; 替换 &rarr; 启动</strong>。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">6.2 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/apply.sh" style="text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word; border-bottom: 1px solid rgb(30, 107, 184);"><code>apply.sh</code></a>：一键替换（已封装上述顺序）</span></h3>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">./apply.sh &lt;new_table.mb&gt; [before.txt]
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	脚本内部的关键几步：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">pkill -TERM -x fcitx; sleep 3                      <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 1) 停（让它把用户词落盘）</span>
cp -p <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span> <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$HOME</span>/wbpy.mb.bak-<span class="hljs-variable" style="color: #986801; line-height: 26px;">$TS</span>&quot;</span>                <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 2) 备份</span>
<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$HERE</span>/mb2txt&quot;</span> <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$NEW</span>&quot;</span> &gt; after.txt                  <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 3) 回读新表</span>
ADD=$(diff &lt;(sort before.txt) &lt;(sort after.txt) | grep -c <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;^&gt;&#39;</span>)
LOST=$(diff &lt;(sort before.txt) &lt;(sort after.txt) | grep -c <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;^&lt;&#39;</span>)
[ <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$LOST</span>&quot;</span> = <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;0&quot;</span> ] || <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">exit</span> 1                        <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 4) 有丢失就中止，不动原库</span>
cp <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$NEW</span>&quot;</span> <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span>; chmod 600 <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span>                   <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 5) 替换</span>
setsid fcitx -d &amp;                                  <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 6) 启动</span>
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	手工等价流程（不用脚本时）：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">MB=<span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$HOME</span>/.config/fcitx/table/wbpy.mb&quot;</span>
pkill -TERM -x fcitx; sleep 3
cp -p <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span> <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$HOME</span>/wbpy.mb.bak-<span class="hljs-variable" style="color: #986801; line-height: 26px;">$(date +%Y%m%d-%H%M%S)</span>&quot;</span>
./mb2txt <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span> &gt; before.txt
python3 merge_wubi.py <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span> cand_wubi.csv after.mb
./mb2txt after.mb &gt; after.txt
diff &lt;(sort before.txt) &lt;(sort after.txt) | grep -c <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;^&gt;&#39;</span>   <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 新增条数</span>
diff &lt;(sort before.txt) &lt;(sort after.txt) | grep -c <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;^&lt;&#39;</span>   <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 必须为 0</span>
cp after.mb <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span> &amp;&amp; chmod 600 <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&quot;<span class="hljs-variable" style="color: #986801; line-height: 26px;">$MB</span>&quot;</span>
setsid fcitx -d &amp;</code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	&nbsp;</h3>
<ul style="box-sizing: border-box; margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 16px; background-color: rgb(255, 255, 255);">
<li style="box-sizing: border-box;">
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
			<span class="content"></p>
<section style="box-sizing: border-box; margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">无图形界面的 shell 里启动 fcitx 需带上会话变量：<code style="box-sizing: border-box; font-size: 14px; font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;">DISPLAY=:0</code>、<code style="box-sizing: border-box; font-size: 14px; font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;">XAUTHORITY=$XDG_RUNTIME_DIR/gdm/Xauthority</code>、<code style="box-sizing: border-box; font-size: 14px; font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;">DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus</code>。</section>
<p></span></h3>
</li>
<li style="box-sizing: border-box;">
		<span class="content"></p>
<section style="box-sizing: border-box; margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">注意 <code style="box-sizing: border-box; font-size: 14px; font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;">fcitx-remote</code> 在没有输入焦点的 shell 里可能返回 0，<strong style="box-sizing: border-box; font-weight: bold; color: black;">不能当判据</strong>；用 <code style="box-sizing: border-box; font-size: 14px; font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;">xprop -root | grep XIM_SERVERS</code>（应含 <code style="box-sizing: border-box; font-size: 14px; font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;">@server=fcitx</code>）或直接打字判断。</section>
<p></span></li>
</ul>
<div style="box-sizing: border-box;">
	&nbsp;</div>
<p><span class="content">6.3 三层验证</span></p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				层次</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				方法</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				通过标准</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				结构</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				官方 <code>mb2txt</code> 回读 + 全量 <code>diff</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				新增条数准确、<strong style="font-weight: bold;">丢失 0</strong></td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				加载</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				fcitx 启动日志、<code>xprop -root \| grep XIM_SERVERS</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				无表相关报错、<code>@server=fcitx</code> 在</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				功能</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				实际打字：唯一码 + 重码各挑几个</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				唯一码直接上屏；重码在候选里（新词排最后）</td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	抽验示例：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">五笔：iiid 泪流满面 / fiml 云淡风轻 / uspy 盖棺定论 / aflf 攻城略地
拼音：leiliuma &rarr; 泪流满面 / yundanfe &rarr; 云淡风轻 / zhifubao &rarr; 支付宝
</code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">6.4 回滚</span></h3>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">./rollback.sh ~/wbpy.mb.bak-YYYYmmdd-HHMMSS
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	建议每批改动前都备份；确认稳定几天后只留最近一份（每个约 10MB）。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content"><span style="font-size: 16px; color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" style="font-size: 16px;" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	7. 经验与坑（按踩坑顺序）</span></h2>
<ol data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">别信&quot;码宽 = 码长 + 1&quot;</strong>。真实是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">pyCodeLen + 1</code>（w bpy 表里是 13）。按 4/5 字节解析会整体错位，且因为同码相邻记录&quot;看起来也对&quot;，很难发现。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">前 4 字节不是词长</strong>。它是码字段的中间部分；词长在码字段之后。第一版解析器能 100% &quot;重建&quot;文件（因为原样拷贝了未知字节），但新记录建不出来 &mdash;&mdash; round-trip 一致性只能证明&quot;读懂了&quot;，不能证明&quot;会写&quot;。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">记录必须按码首字符分组</strong>，否则引擎索引失效。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">同码先后 = 文件先后</strong>，插入位置即候选位置。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">iIndex</code> 用全局最大值 +1</strong>，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">iHit</code> 新词写 0，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">type</code>：五笔 0、拼音 1（写错会被当拼音/提示记录）。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">拼音码截断到 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">pyCodeLen</code></strong>（12），但因为是前缀匹配，照样可用。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">拼音码若与&quot;唯一候选的五笔码&quot;同码</strong>，会破坏&quot;唯一即上屏&quot;，应跳过。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">fcitx 退出会重写 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">.mb</code></strong>，所以顺序不能颠倒；重建要基于&quot;停之后&quot;的最新文件。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">拼音词库 &ne; 词表</strong>。<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">有多</code>/<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">人是</code>/<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">的时候</code> 是整句解码的 n-gram，必须靠 PMI + 词表交叉剔除。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">4 字词噪音最大</strong>，不要只按词频排；用成语库精确匹配效果最好。</section>
</li>
</ol>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">8. 一次完整操作清单（checklist）</span></h2>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">[ ] git <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">clone</span> https://github.com/codelast/update-freewb-dict-on-linux.git &amp;&amp; <span class="hljs-built_in" style="color: #c18401; line-height: 26px;">cd</span> update-freewb-dict-on-linux   <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 拿到脚本</span>
[ ] ./build_mb2txt.sh                        <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 编译官方工具</span>
[ ] ./mb2txt &lt;词库.mb&gt; &gt; dump.txt             <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 差集基准 + 单字码/读音来源</span>
[ ] 下载外部词库（白霜 / 墨奇 / 现汉词表 / 成语库）
[ ] python3 filter_candidates.py ... &gt; cand.csv
[ ] 人工抽验候选（TOP + 中段随机）
[ ] python3 merge_wubi.py   &lt;源.mb&gt; cand.csv  after.mb
[ ] 可选：python3 gen_pinyin.py / merge_pinyin.py
[ ] ./mb2txt after.mb &gt; after.txt；diff 校验：新增对、丢失 0
[ ] ./apply.sh after.mb          <span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 停服&rarr;备份&rarr;校验&rarr;替换&rarr;重启</span>
[ ] 日志无报错 + xprop 有 fcitx + 实打若干词
[ ] 记下备份路径与回滚命令
</code></pre>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">附：常用命令速查</span></h2>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		以下命令均需在仓库目录下执行。</p>
</blockquote>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;"><span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 查看表结构（文本形式）</span>
./mb2txt ~/.config/fcitx/table/wbpy.mb | head -20

<span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 统计词条数 / 拼音记录数</span>
./mb2txt ~/.config/fcitx/table/wbpy.mb | sed -n <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;/<p style='text-align:center;'><span class='MathJax_Preview'>\[Data\]</span><script type='math/tex;  mode=display'>Data</script></p>/,$p&#39;</span> | tail -n +2 | wc -l
./mb2txt ~/.config/fcitx/table/wbpy.mb | grep -c <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;^@&#39;</span>

<span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 按码查词</span>
./mb2txt ~/.config/fcitx/table/wbpy.mb | grep <span class="hljs-string" style="color: #50a14f; line-height: 26px;">&#39;^rdug &#39;</span>

<span class="hljs-comment" style="color: #a0a1a7; font-style: italic; line-height: 26px;"># 重启输入法</span>
fcitx -r
</code></pre>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		全部操作只在 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">~/.config/fcitx/table/</code>（词库与备份）与仓库目录（脚本）内进行，不改动系统文件。</p>
</blockquote>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">附：授权与合规（数据来源）</span></h2>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				组件</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				来源</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				许可证</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				用途</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				白霜五笔</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>gaboolic/rime-frost</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GPL-3.0</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				主要词源 + 现代词频</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				墨奇五笔</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>gaboolic/rime-wubi-sentence</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				MIT</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				新词/专名</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				雾凇拼音（白霜上游）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>iDvel/rime-ice</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GPL-3.0</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				间接继承</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				成语库</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>pwxcoo/chinese-xinhua</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				MIT</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				4 字成语判定</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				现代汉语常用词表</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				gist（2014）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				无声明（默认保留）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				仅作&quot;是否成词&quot;判据，未复制内容</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				fcitx4 源码</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>fcitx/fcitx</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GPL-2.0</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				编译本地校验工具</td>
</tr>
</tbody>
</table>
</section>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">本项目代码以 <strong style="font-weight: bold; color: black;">MIT</strong> 发布（见仓库 <a href="https://github.com/codelast/update-freewb-dict-on-linux/blob/main/LICENSE" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;"><code style="font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; background-color: rgba(27, 31, 35, 0.05); font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; word-break: break-all;">LICENSE</code></a>）。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">本机自用（不分发）</strong>：GPL/MIT 的义务都不触发，无风险。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">若要分发产出的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">.mb</code></strong>：GPL-3.0 部分需提供生成脚本并同许可；MIT 部分保留版权声明；用户自定义词条版权归用户。</section>
</li>
</ul>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span> 版权声明 <span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</section>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8-ubuntu-%e4%b8%8a%e6%9b%b4%e6%96%b0%e3%80%8c%e6%9e%81%e7%82%b9%e4%ba%94%e7%ac%94%e3%80%8d%e8%af%8d%e5%ba%93%ef%bc%88fcitx4-%e7%a0%81%e8%a1%a8%ef%bc%89/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 有些Windows软件的技术栈真的好老</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%9c%89%e4%ba%9bwindows%e8%bd%af%e4%bb%b6%e7%9a%84%e6%8a%80%e6%9c%af%e6%a0%88%e7%9c%9f%e7%9a%84%e5%a5%bd%e8%80%81/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%9c%89%e4%ba%9bwindows%e8%bd%af%e4%bb%b6%e7%9a%84%e6%8a%80%e6%9c%af%e6%a0%88%e7%9c%9f%e7%9a%84%e5%a5%bd%e8%80%81/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Tue, 29 Sep 2026 06:54:03 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[AxMath]]></category>
		<category><![CDATA[移植Linux]]></category>
		<category><![CDATA[软件技术栈]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14273</guid>

					<description><![CDATA[<section data-tool="markdown2wechat编辑器" data-website="https://aizhuanqian.com" id="nice" style="font-size: 16px; padding: 0px 10px; line-height: 1.6; letter-spacing: 0px; word-break: break-word; overflow-wrap: break-word; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">
<h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 24px;">
	<span class="content">有些Windows软件的技术栈真的好老</span></h1>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		一个 2025 年 7 月发布的安装包，拆开一看，内核停留在 2008 年。</p>
</blockquote>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">1、起因：只是想看看能不能搬到 Linux</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	事情很简单。我手上有一个 Windows 安装包 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">AxMath_Setup_Win_20250713_EN.exe</code>（AxMath，一款小众的数学公式编辑器），我是它的正版注册用户，但我想着能不能在Ubuntu下，用非Wine的方式、非虚拟机的方式使用它呢？这就涉及把它移植到Ubuntu的问题了&#8212;&#8212;如果它是基于Electron之类跨平台的框架开发的，那还真有可能。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	文件名里写着 20250713，也就是 2025 年 7 月发布的版本。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	所以就把它拆包看看。<br />
	<span id="more-14273"></span></p>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">2、拆开之后：考古现场</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	安装包是 NSIS 自解压格式，用 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">7z</code> 一把就解开了：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">7z&#160;x&#160;AxMath_Setup_Win_20250713_EN.exe&#160;-o&#160;extracted
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	里面的东西很有意思：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">AxMath.exe&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;主程序
AxSnap.exe&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;截图/OCR&#160;工具
Register.exe&#160;&#160;&#160;&#160;&#160;&#160;授权注册
AxLaTeX.dll&#160;&#160;&#160;&#160;&#160;&#160;&#160;LaTeX&#160;渲染
AxBDH.dll&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Office&#160;桥接
Microsoft.VC90.MFC/mfc90u.dll&#160;&#160;&#160;&#160;&#160;&#160;&#8592;&#160;注意这个
gdiplus.assembly/GdiPlus.dll
libeay32.dll&#160;/&#160;ssleay32.dll&#160;/&#160;libcurl.dll
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">Microsoft.VC90.MFC</code> 这个目录名就是线索：<strong style="font-weight: bold;">VC90 = Visual C++ 2008</strong>。也就是说，这个 2025 年的软件，跑在 2008 年的运行时上。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%9c%89%e4%ba%9bwindows%e8%bd%af%e4%bb%b6%e7%9a%84%e6%8a%80%e6%9c%af%e6%a0%88%e7%9c%9f%e7%9a%84%e5%a5%bd%e8%80%81/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<section data-tool="markdown2wechat编辑器" data-website="https://aizhuanqian.com" id="nice" style="font-size: 16px; padding: 0px 10px; line-height: 1.6; letter-spacing: 0px; word-break: break-word; overflow-wrap: break-word; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;">
<h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 24px;">
	<span class="content">有些Windows软件的技术栈真的好老</span></h1>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		一个 2025 年 7 月发布的安装包，拆开一看，内核停留在 2008 年。</p>
</blockquote>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">1、起因：只是想看看能不能搬到 Linux</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	事情很简单。我手上有一个 Windows 安装包 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">AxMath_Setup_Win_20250713_EN.exe</code>（AxMath，一款小众的数学公式编辑器），我是它的正版注册用户，但我想着能不能在Ubuntu下，用非Wine的方式、非虚拟机的方式使用它呢？这就涉及把它移植到Ubuntu的问题了&mdash;&mdash;如果它是基于Electron之类跨平台的框架开发的，那还真有可能。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	文件名里写着 20250713，也就是 2025 年 7 月发布的版本。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	所以就把它拆包看看。<br />
	<span id="more-14273"></span></p>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">2、拆开之后：考古现场</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	安装包是 NSIS 自解压格式，用 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">7z</code> 一把就解开了：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">7z&nbsp;x&nbsp;AxMath_Setup_Win_20250713_EN.exe&nbsp;-o&nbsp;extracted
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	里面的东西很有意思：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">AxMath.exe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;主程序
AxSnap.exe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;截图/OCR&nbsp;工具
Register.exe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;授权注册
AxLaTeX.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LaTeX&nbsp;渲染
AxBDH.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Office&nbsp;桥接
Microsoft.VC90.MFC/mfc90u.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&larr;&nbsp;注意这个
gdiplus.assembly/GdiPlus.dll
libeay32.dll&nbsp;/&nbsp;ssleay32.dll&nbsp;/&nbsp;libcurl.dll
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">Microsoft.VC90.MFC</code> 这个目录名就是线索：<strong style="font-weight: bold;">VC90 = Visual C++ 2008</strong>。也就是说，这个 2025 年的软件，跑在 2008 年的运行时上。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	再用 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">objdump</code> 一验，实锤：</p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				项目</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				实测值</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				含义</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				PE 架构</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				PE32 (x86)</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">32 位</strong></td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				MajorLinkerVersion</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">9.0</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Visual Studio<strong style="font-weight: bold;">2008</strong> 的链接器</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				附带运行库</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>mfc90u.dll</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				MFC 9.0 = VC++ 2008</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				主程序时间戳</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">2025-07-13</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				编译日期很新</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				捆绑 OpenSSL</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">1.0.2d（2015-07-09）</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				早已 EOL</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				捆绑 libcurl</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">7.45.0（2015）</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				十年前的东西</td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	一边是 2025 年的时间戳，一边是 2008 年的工具链和 2015 年的第三方库。</p>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">3、2025年的软件版本竟然还是32位的</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	很多人的第一反应是：2025年的版本还是32位的？但对这类软件来说，这几乎是必然的。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">3.1 迁移成本和收益不成比例</strong> 一个 MFC 老代码库要从 32 位迁到 64 位、从 VC9 迁到新工具链，构建脚本、第三方依赖、COM 注册&hellip;&hellip;全都得动。而 32 位程序在 64 位 Windows 上靠 WOW64 照样跑，用户完全无感，对小软件团队来说没动力迁移。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">3.2 Office 加载项的&quot;位数枷锁&quot;</strong> AxMath 的核心价值是嵌进 Word / Excel / WPS。它的 COM 组件必须和宿主 Office 的位数一致，而 32 位 Office / WPS 装机量巨大&mdash;&mdash;跟着做 32 位最省事。解包里能看到一堆加载项：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">AxMath.dotm&nbsp;&nbsp;&nbsp;&rarr;&nbsp;Word（含&nbsp;VBA&nbsp;宏）
AxMath.xlam&nbsp;&nbsp;&nbsp;&rarr;&nbsp;Excel
AxMath.ppam&nbsp;&nbsp;&nbsp;&rarr;&nbsp;PowerPoint
WPS/STARTUP/AxMath.dotm&nbsp;&rarr;&nbsp;WPS
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">3.3 轻量应用根本用不上 64 位的好处</strong> 一个公式编辑器，内存占用远不到 2GB。64 位最大的优势（大内存寻址）在这儿毫无意义。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">4、安全问题</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	技术栈老，本身只是&quot;不优雅&quot;。但当我们把范围从&quot;好不好看&quot;换成&quot;安不安全&quot;，问题就严肃了。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">4.1 授权走的是明文 HTTP</strong> <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">Register.exe</code> 里的联网地址是（注意是 UTF-16 宽字符存的，普通搜索搜不到）：</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;">
<code class="hljs" style="display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">http://www.axmath.cn:6150/@@@&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&larr;&nbsp;授权服务器
http://121.199.3.143:6150/@@@&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&larr;&nbsp;硬编码备用&nbsp;IP
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	激活码、机器指纹，就这么明文发出去了。在公共 WiFi 下，同网段的攻击者抓个包就能拿到激活码&mdash;&mdash;不需要任何漏洞利用技巧。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">4.2 2015 年的 OpenSSL 1.0.2d</strong> 这个版本之后修的所有 CVE 它都带着。比如 CVE-2016-2107（AES-NI padding oracle），中间人可以利用它解密 HTTPS 会话&mdash;&mdash;也就是说，&quot;用了 HTTPS&quot;在这个版本上并不等于安全。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">4.3 承载漏洞的库没开内存防护</strong></p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				文件</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				DllCharacteristics</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				含义</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>Register.exe</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				0x8140</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				ASLR + DEP</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>libcurl.dll</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				0x0140</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				ASLR + DEP</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>libeay32.dll</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">0x0000</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">无 ASLR、无 DEP</strong></td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	名词解释：</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">ASLR</strong>（Address Space Layout Randomization，地址空间布局随机化）：每次程序启动时，把代码、数据、DLL 等加载到随机的内存地址。这样攻击者就无法预知某个函数或数据的固定地址，构造可靠的利用会变得困难。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">DEP</strong>（Data Execution Prevention，数据执行保护，即 NX）：把内存里的数据区标记为&quot;不可执行&quot;。即使攻击者把恶意代码写进了内存，CPU 也会拒绝执行它，从而挡掉一大类&quot;写入即执行&quot;的攻击。</section>
</li>
</ul>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	一旦 libcurl（7.45.0 存在越界写类漏洞，如 CVE-2016-8617）或 OpenSSL 触发内存破坏，这个&quot;裸奔&quot;的 DLL 会让利用门槛大幅降低。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span> 版权声明 <span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</section>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%9c%89%e4%ba%9bwindows%e8%bd%af%e4%bb%b6%e7%9a%84%e6%8a%80%e6%9c%af%e6%a0%88%e7%9c%9f%e7%9a%84%e5%a5%bd%e8%80%81/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 如何判断已经启动的TF-Serving服务是否正在使用</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 16 Sep 2024 04:27:03 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[TF-Serving]]></category>
		<category><![CDATA[TFServing]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14136</guid>

					<description><![CDATA[<p>在一台服务器上，如果启动了一个TF-Serving服务，我们知道它占了资源，却不知道它是在空跑还是<span style="color:#ff0000;">真的在用</span>。<br />
本文描述了怎样判断它是否真的在用。<br />
<span id="more-14136"></span></p>
<div>
	用 nvidia-smi 命令能看到 TF-Serving 服务在运行：</div>
<p><img decoding="async" alt="TF-Serving is running" src="https://www.codelast.com/wp-content/uploads/2024/09/tf_serving_running.png" style="width: 700px; height: 149px;" /></p>
<div>
<div>
		其进程id是 22871，于是进一步查询这个进程的信息：</div>
<blockquote>
<div>
			ps -ef &#124; grep 22871</div>
</blockquote>
<div>
		输出类似于：</div>
<blockquote>
<div>
			root&#160; &#160; &#160;22871 22729 83 13:42 pts/0&#160; &#160; 00:06:35 tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=codelast --model_base_path=/models/codelast</div>
</blockquote>
<div>
		可见其REST服务的端口号为 8501。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>
<div>
			于是我们可以用 tcpdump 来捕获并分析流量，运行以下命令(需要 root 权限)：：</div>
<blockquote>
<div>
				sudo tcpdump -vv -i any &#39;port 8501&#39;</div>
</blockquote>
<div>
			如果有客户端正在向这个TF-Serving服务发送请求，我们应会看到这个命令有输出，不断在刷屏，类似于：
<div>
				<span style="color:#0000ff;">14:27:59.174425 IP (tos 0x0, ttl 60, id 51707, offset 0, flags [DF], proto TCP (6), length 1500)</span></div>
<div>
				<span style="color:#0000ff;">node.codelast.com.60679</span></div></div></div></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>在一台服务器上，如果启动了一个TF-Serving服务，我们知道它占了资源，却不知道它是在空跑还是<span style="color:#ff0000;">真的在用</span>。<br />
本文描述了怎样判断它是否真的在用。<br />
<span id="more-14136"></span></p>
<div>
	用 nvidia-smi 命令能看到 TF-Serving 服务在运行：</div>
<p><img decoding="async" alt="TF-Serving is running" src="https://www.codelast.com/wp-content/uploads/2024/09/tf_serving_running.png" style="width: 700px; height: 149px;" /></p>
<div>
<div>
		其进程id是 22871，于是进一步查询这个进程的信息：</div>
<blockquote>
<div>
			ps -ef | grep 22871</div>
</blockquote>
<div>
		输出类似于：</div>
<blockquote>
<div>
			root&nbsp; &nbsp; &nbsp;22871 22729 83 13:42 pts/0&nbsp; &nbsp; 00:06:35 tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=codelast --model_base_path=/models/codelast</div>
</blockquote>
<div>
		可见其REST服务的端口号为 8501。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<div>
			于是我们可以用 tcpdump 来捕获并分析流量，运行以下命令(需要 root 权限)：：</div>
<blockquote>
<div>
				sudo tcpdump -vv -i any &#39;port 8501&#39;</div>
</blockquote>
<div>
			如果有客户端正在向这个TF-Serving服务发送请求，我们应会看到这个命令有输出，不断在刷屏，类似于：</p>
<div>
				<span style="color:#0000ff;">14:27:59.174425 IP (tos 0x0, ttl 60, id 51707, offset 0, flags [DF], proto TCP (6), length 1500)</span></div>
<div>
				<span style="color:#0000ff;">node.codelast.com.60679 &gt; 172.17.0.2.cmtp-mgt: Flags [.], cksum 0x310f (correct), seq 617580:619040, ack 1, win 63, length 1460</span></div>
<div>
				<span style="color:#0000ff;">14:27:59.174453 IP (tos 0x0, ttl 60, id 39347, offset 0, flags [DF], proto TCP (6), length 1500)</span></div>
<div>
				<span style="color:#0000ff;">node.codelast.com.32739 &gt; 172.17.0.2.cmtp-mgt: Flags [.], cksum 0x9354 (correct), seq 44268904:44270364, ack 1, win 86, length 1460</span></div>
<p>			如果没有请求发到TF-Serving服务，那么上面的命令什么都不会输出，就表明TF-Serving服务没在用。<br />
			<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
			<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
			转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
			感谢关注我的微信公众号（微信扫一扫）：<br />
			<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
			以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
				<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</p></div>
<p>
		&nbsp;</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 解决IntelliJ idea启动崩溃：error occurred during error reporting (), id 0x6, SIGABRT (0x6) at pc=...</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Fri, 15 Mar 2024 09:48:13 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[IntelliJ IDEA]]></category>
		<category><![CDATA[SIGABRT]]></category>
		<category><![CDATA[启动]]></category>
		<category><![CDATA[崩溃]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14081</guid>

					<description><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2024/03/intellij_idea_logo.jpeg" style="width: 225px; height: 225px;" /></div>
<p>有时候，一个用了好久、一直好用的方法突然失灵，并且还折腾了几天，真的会逼疯人。<br />
前几天我就遇到了这种破事：在Ubuntu开发机上自己升级IntelliJ idea到最新版之后，就无法再启动它。<br />
启动时永远会崩溃，无论是重启系统、删除IntelliJ idea的本地缓存，或者使用回旧版，都无法再启动它（仿佛什么文件被&#34;污染&#34;了，再也回不去了），十分烦人。经过几天各种方法的尝试，终于解决了问题，我的解决办法不具有普适性，但如果你遇到了此类问题，或许可以为你提供一些解决思路。<br />
<span id="more-14081"></span><br />
OS：<span style="color:#0000ff;">Ubuntu 20.04.6 LTS</span><br />
JDK：<span style="color:#0000ff;">1.8.0_382</span><br />
原来安装的IntelliJ idea版本：<span style="color:#b22222;">idea-IC-232.8660.185</span><br />
从JetBrains官网上下载的新版IntelliJ idea版本：<span style="color:#b22222;">idea-IC-233.14808.21</span><br />
我当时不是利用IDE里的升级功能来升级的，而是自己下载了新版的压缩包，解压出来一个&#160;idea-IC-233.14808.21 目录，直接进入 bin 目录下执行 idea.sh 来跑的新版。众所周知，这样跑起来之后，新版会自动把旧版里的配置引入进来，只要没有问题，是可以无缝切换到新版不需要重新配置的。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
然而，启动新版的时候挂了，最后看到命令行报错：</p>
<blockquote>
<div>
		[error occurred during error reporting (), id 0x6, SIGABRT (0x6) at pc=0x00007fed3c5cf00b]</div>
<div>
		Aborted (core dumped)</div>
</blockquote>
<div>
	进不了IDE主界面。同时在/home目录下生成了一个内容超长的错误报告文件 java_error_in_idea_xxx.log</div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2024/03/intellij_idea_logo.jpeg" style="width: 225px; height: 225px;" /></div>
<p>有时候，一个用了好久、一直好用的方法突然失灵，并且还折腾了几天，真的会逼疯人。<br />
前几天我就遇到了这种破事：在Ubuntu开发机上自己升级IntelliJ idea到最新版之后，就无法再启动它。<br />
启动时永远会崩溃，无论是重启系统、删除IntelliJ idea的本地缓存，或者使用回旧版，都无法再启动它（仿佛什么文件被&quot;污染&quot;了，再也回不去了），十分烦人。经过几天各种方法的尝试，终于解决了问题，我的解决办法不具有普适性，但如果你遇到了此类问题，或许可以为你提供一些解决思路。<br />
<span id="more-14081"></span><br />
OS：<span style="color:#0000ff;">Ubuntu 20.04.6 LTS</span><br />
JDK：<span style="color:#0000ff;">1.8.0_382</span><br />
原来安装的IntelliJ idea版本：<span style="color:#b22222;">idea-IC-232.8660.185</span><br />
从JetBrains官网上下载的新版IntelliJ idea版本：<span style="color:#b22222;">idea-IC-233.14808.21</span><br />
我当时不是利用IDE里的升级功能来升级的，而是自己下载了新版的压缩包，解压出来一个&nbsp;idea-IC-233.14808.21 目录，直接进入 bin 目录下执行 idea.sh 来跑的新版。众所周知，这样跑起来之后，新版会自动把旧版里的配置引入进来，只要没有问题，是可以无缝切换到新版不需要重新配置的。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
然而，启动新版的时候挂了，最后看到命令行报错：</p>
<blockquote>
<div>
		[error occurred during error reporting (), id 0x6, SIGABRT (0x6) at pc=0x00007fed3c5cf00b]</div>
<div>
		Aborted (core dumped)</div>
</blockquote>
<div>
	进不了IDE主界面。同时在/home目录下生成了一个内容超长的错误报告文件 java_error_in_idea_xxx.log<br />
	我一开始并没有看这个log文件，而是按网上搜到的方法，分别尝试了：<br />
	1、重启系统<br />
	2、删除IntelliJ idea的缓存<br />
	3、使用回旧版IntelliJ idea<br />
	4、仿照<a href="https://youtrack.jetbrains.com/issue/IDEA-315192/IntelliJ-would-not-open-after-being-closed-once-on-Ubuntu-22.04-LTS.-The-only-solution-is-rebooting." rel="noopener" target="_blank">这个</a>类似的问题，卸载了snap又重新安装<br />
	以上方法都没用。<br />
	实在没辙了，只能硬着头皮看崩溃产生的日志文件&nbsp;java_error_in_idea_xxx.log，没想到一看就发现了端倪。<br />
	开头有一段内容是：</p>
<div>
<blockquote>
<div>
				# Problematic frame:</div>
<div>
				# C&nbsp; [x86_64-linux-gnu-tree-sitter-cpp.so+0x38ec09]&nbsp; tree_sitter_cpp_external_scanner_deserialize+0x179</div>
</blockquote>
<div>
<div>
				虽然我不知道它是什么确切的意思，但是这里写的是&quot;问题帧&quot;，说明崩溃和它有关。<br />
				<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></div>
<div>
				再往下看日志，会看到：</p>
<blockquote>
<div>
						---------------&nbsp; T H R E A D&nbsp; ---------------</div>
<div>
						&nbsp;</div>
<div>
						Current thread (0x00007fec7c02b370):&nbsp; JavaThread &quot;AWT-EventQueue-0&quot; [_thread_in_native, id=352672, stack(0x00007feb95ae5000,0x00007feb95be6000)]</div>
<div>
						&nbsp;</div>
<div>
						Stack: [0x00007feb95ae5000,0x00007feb95be6000],&nbsp; sp=0x00007feb95be0310,&nbsp; free space=1004k</div>
<div>
						Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter-cpp.so+0x38ec09]&nbsp; tree_sitter_cpp_external_scanner_deserialize+0x179</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter.so+0x30b3e]&nbsp; ts_parser_reset+0x30e</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter.so+0x2e329]&nbsp; ts_parser_set_language+0x399</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter.so+0xb4875]&nbsp; Java_org_treesitter_TSParser_ts_1parser_1set_1language+0x25</div>
<div>
						j&nbsp; org.treesitter.TSParser.ts_parser_set_language(JJ)Z+0</div>
<div>
						j&nbsp; org.treesitter.TSParser.setLanguage(Lorg/treesitter/TSLanguage;)Z+10</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.d.a()V+64</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.d.&lt;init&gt;()V+365</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.d.a()Lai/codegeex/plugin/lang/agent/d;+10</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.CodegeexAgentCompletionService.e()V+0</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.CodegeexAgentCompletionService.&lt;init&gt;()V+266</div>
</blockquote>
<div>
<div>
						可见，和出问题的&quot;x86_64-linux-gnu-tree-sitter-cpp.so+0x38ec09&quot;有关系的插件，第一个出现的就是&quot;ai.codegeex.plugin&quot;，这个对应的就是我安装的CodeGeeX插件。</div>
<div>
						所以我怀疑，删除这个插件可以解决IntelliJ idea启动崩溃的问题。</div>
<div>
						在Ubuntu系统上，插件安装在这个目录下：<span style="color:#0000ff;">~/.local/share/JetBrains/IdeaIC2023.3</span></div>
<div>
						其中，IdeaIC2023.3是IntelliJ idea的版本号，每升级一个版本，~/.local/share/JetBrains 目录下都会生成一个新的目录。</div>
<div>
						在这个目录下，会看到有一个名为&quot;CodeGeeX&quot;的目录，这个目录就是CodeGeeX插件的安装目录，删除它即可。</div>
<div>
						然后再次尝试启动IntelliJ idea，发现已经可以正常启动了。<br />
						虽然我现在还不知道为什么CodeGeeX插件会引起这个问题，但是如果你像我一样，实在找不到IDE崩溃的原因时，删除可能有问题的插件或许是解决问题的一个办法。<br />
						<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
						<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
						转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
						感谢关注我的微信公众号（微信扫一扫）：<br />
						<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
						以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
							<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</p></div>
</p></div>
</p></div>
</p></div>
</p></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>如何查看指定的Hadoop(HDFS)目录的配额</title>
		<link>https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/</link>
					<comments>https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 11 May 2023 09:12:49 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[hadoop fs -count -q]]></category>
		<category><![CDATA[Hadoop目录配额]]></category>
		<category><![CDATA[HDFS目录配额]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13908</guid>

					<description><![CDATA[<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &#34;Segoe UI&#34;, Roboto, &#34;Helvetica Neue&#34;, Arial, &#34;Noto Sans&#34;, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	Hadoop目录的配额是指为了限制一个HDFS文件夹中所包含的数据块和名称空间元素（如子文件夹和文件）的数量而设置的最大值。简单来说，就是对一个文件夹中可存储数据的上限进行管理和控制，以便于维护整个系统的健康和性能。</p>
<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &#34;Segoe UI&#34;, Roboto, &#34;Helvetica Neue&#34;, Arial, &#34;Noto Sans&#34;, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	通过设置适当的配额，管理员可以确保每个目录不会超出其可承受的容量范围，防止集群资源被长时间占用或滥用。同时也可以通过监视使用情况来优化系统性能并减少故障风险。</p>
<p><span id="more-13908"></span></p>
<p>
	使用 <span style="color:#ff0000;">hadoop fs -count -q&#160;</span><span style="color:#0000ff;">&#60;your_hdfs_dir&#62;</span> 命令可以查看指定目录的配额，该命令输出有八列，以下是每列的含义：</p>
<ul>
<li>
		QUOTA：文件和目录的总数限制</li>
<li>
		REMAINING_QUOTA：该用户可以创建的剩余文件和目录总数</li>
<li>
		SPACE_QUOTA：授予该用户的空间配额</li>
<li>
		REMAINING_SPACE_QUOTA：该用户剩余的空间配额</li>
<li>
		DIR_COUNT：当前目录总数</li>
<li>
		FILE_COUNT：当前文件总数</li>
<li>
		CONTENT_SIZE：当前文件大小</li>
<li>
		PATH_NAME：目录路径</li>
</ul>
<p></p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&#160;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" />&#8230; <a href="https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	Hadoop目录的配额是指为了限制一个HDFS文件夹中所包含的数据块和名称空间元素（如子文件夹和文件）的数量而设置的最大值。简单来说，就是对一个文件夹中可存储数据的上限进行管理和控制，以便于维护整个系统的健康和性能。</p>
<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	通过设置适当的配额，管理员可以确保每个目录不会超出其可承受的容量范围，防止集群资源被长时间占用或滥用。同时也可以通过监视使用情况来优化系统性能并减少故障风险。</p>
<p><span id="more-13908"></span></p>
<p>
	使用 <span style="color:#ff0000;">hadoop fs -count -q&nbsp;</span><span style="color:#0000ff;">&lt;your_hdfs_dir&gt;</span> 命令可以查看指定目录的配额，该命令输出有八列，以下是每列的含义：</p>
<ul>
<li>
		QUOTA：文件和目录的总数限制</li>
<li>
		REMAINING_QUOTA：该用户可以创建的剩余文件和目录总数</li>
<li>
		SPACE_QUOTA：授予该用户的空间配额</li>
<li>
		REMAINING_SPACE_QUOTA：该用户剩余的空间配额</li>
<li>
		DIR_COUNT：当前目录总数</li>
<li>
		FILE_COUNT：当前文件总数</li>
<li>
		CONTENT_SIZE：当前文件大小</li>
<li>
		PATH_NAME：目录路径</li>
</ul>
<p></p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 如何下载HLS流视频文件</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Wed, 03 May 2023 10:12:39 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[下载HLS]]></category>
		<category><![CDATA[下载m3u8]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13899</guid>

					<description><![CDATA[<p>在互联网上，有些视频以HLS流的形式呈现，当你用一些工具捕获到它的播放地址时，会发现是一个以 .m3u8&#160;结尾的URL。<br />
那么，什么是 HLS&#160;和&#160;m3u8&#160;呢？</p>
<blockquote>
<p>
		HLS（HTTP Live Streaming）是一种基于HTTP协议的流媒体传输协议，而M3U8则是一种基于文本的播放列表文件格式。在HLS中，媒体数据被划分成多个小文件进行传输，并使用M3U8文件作为索引来指向这些媒体数据文件。M3U8文件包含了所有的媒体数据文件的URL地址及其相关信息，如码率、分辨率、编码格式等。因此，当一个客户端请求播放一个HLS流时，它将下载对应的M3U8索引文件，并且根据其中包含的地址去下载其他的媒体数据文件。简单来说，HLS和M3U8是两个不同但紧密相连的概念，其中M3U8作为HLS协议中索引与定位资源的重要组成部分。</p>
</blockquote>
<p>问题来了：如何下载HLS流视频文件呢？<br />
<span id="more-13899"></span><br />
有多种方法，下面略举一二。</p>
<p><span style="background-color: rgb(0, 255, 0);">➤</span>&#160;使用Chrome插件：<span style="color:#0000ff;">Video DownloadHelper</span><br />
这个插件可以捕获视频地址，也可以直接下载。但是直接下载HLS流视频每天有次数限制（很久以前是这样，不知道现在是什么情况），所以用此插件直接下载不可取。<br />
那么我们可以用它获取视频地址，再用类似于 <a href="https://github.com/HeiSir2014/M3U8-Downloader" rel="noopener" target="_blank">M3U8-Downloader</a>&#160;这样的桌面软件去下载这个地址指向的视频。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0);">➤</span>&#160;使用跨平台的HLS下载工具&#160;<span style="color:#0000ff;">N_m3u8DL-RE</span><br />
<a href="https://github.com/nilaoda/N_m3u8DL-RE" rel="noopener" target="_blank">N_m3u8DL-RE</a>&#160;是一款跨平台的DASH/HLS/MSS下载工具，功能很强大。<br />
以Ubuntu Linux系统为例，只需简单地下载其release包，解压出来得到一个可执行程序&#160;N_m3u8DL-RE，然后这样用就可以下载HLS流视频了：</p>
<blockquote>
<p>
		./N_m3u8DL-RE &#60;m3u8_url&#62;</p>
</blockquote>
<p>N_m3u8DL-RE&#160;支持的参数非常多，可以参考其文档。<br />
如果首次运行的时候提示没有安装 ffmpeg，可以用 apt install ffmpeg&#160;安装，再运行。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>在互联网上，有些视频以HLS流的形式呈现，当你用一些工具捕获到它的播放地址时，会发现是一个以 .m3u8&nbsp;结尾的URL。<br />
那么，什么是 HLS&nbsp;和&nbsp;m3u8&nbsp;呢？</p>
<blockquote>
<p>
		HLS（HTTP Live Streaming）是一种基于HTTP协议的流媒体传输协议，而M3U8则是一种基于文本的播放列表文件格式。在HLS中，媒体数据被划分成多个小文件进行传输，并使用M3U8文件作为索引来指向这些媒体数据文件。M3U8文件包含了所有的媒体数据文件的URL地址及其相关信息，如码率、分辨率、编码格式等。因此，当一个客户端请求播放一个HLS流时，它将下载对应的M3U8索引文件，并且根据其中包含的地址去下载其他的媒体数据文件。简单来说，HLS和M3U8是两个不同但紧密相连的概念，其中M3U8作为HLS协议中索引与定位资源的重要组成部分。</p>
</blockquote>
<p>问题来了：如何下载HLS流视频文件呢？<br />
<span id="more-13899"></span><br />
有多种方法，下面略举一二。</p>
<p><span style="background-color: rgb(0, 255, 0);">➤</span>&nbsp;使用Chrome插件：<span style="color:#0000ff;">Video DownloadHelper</span><br />
这个插件可以捕获视频地址，也可以直接下载。但是直接下载HLS流视频每天有次数限制（很久以前是这样，不知道现在是什么情况），所以用此插件直接下载不可取。<br />
那么我们可以用它获取视频地址，再用类似于 <a href="https://github.com/HeiSir2014/M3U8-Downloader" rel="noopener" target="_blank">M3U8-Downloader</a>&nbsp;这样的桌面软件去下载这个地址指向的视频。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0);">➤</span>&nbsp;使用跨平台的HLS下载工具&nbsp;<span style="color:#0000ff;">N_m3u8DL-RE</span><br />
<a href="https://github.com/nilaoda/N_m3u8DL-RE" rel="noopener" target="_blank">N_m3u8DL-RE</a>&nbsp;是一款跨平台的DASH/HLS/MSS下载工具，功能很强大。<br />
以Ubuntu Linux系统为例，只需简单地下载其release包，解压出来得到一个可执行程序&nbsp;N_m3u8DL-RE，然后这样用就可以下载HLS流视频了：</p>
<blockquote>
<p>
		./N_m3u8DL-RE &lt;m3u8_url&gt;</p>
</blockquote>
<p>N_m3u8DL-RE&nbsp;支持的参数非常多，可以参考其文档。<br />
如果首次运行的时候提示没有安装 ffmpeg，可以用 apt install ffmpeg&nbsp;安装，再运行。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 设置Emacs打开一个文件时的&quot;文件太大&quot;警告阈值</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 24 Apr 2023 03:56:36 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[large file warning]]></category>
		<category><![CDATA[文件太大警告]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13891</guid>

					<description><![CDATA[<div>
	每次用emacs打开一个比较大的文件时，它都提示：</div>
<blockquote>
<div>
		File xxx is large (XXXMB), really open? (y or n)</div>
</blockquote>
<div>
	此时必须要按 y 才能继续打开此文件。</div>
<div>
	有没有办法调整这个文件大小的阈值，从而让它不那么烦人？<br />
	<span id="more-13891"></span><br />
	方法是：修改 ~/.emacs 文件，在里面添加如下配置：
<blockquote>
<div>
			;; set large file warning&#160;threshold when opening it</div>
<div>
			(setq large-file-warning-threshold (* 1024 1024 1024))</div>
</blockquote>
<p>	这表示当文件&#62;1GB时才会提示&#8220;文件太大&#8221;的警告，不超过1GB的文件直接就打开了，不需要用户按 y 确认。</p>
<p>
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u></p></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<div>
	每次用emacs打开一个比较大的文件时，它都提示：</div>
<blockquote>
<div>
		File xxx is large (XXXMB), really open? (y or n)</div>
</blockquote>
<div>
	此时必须要按 y 才能继续打开此文件。</div>
<div>
	有没有办法调整这个文件大小的阈值，从而让它不那么烦人？<br />
	<span id="more-13891"></span><br />
	方法是：修改 ~/.emacs 文件，在里面添加如下配置：</p>
<blockquote>
<div>
			;; set large file warning&nbsp;threshold when opening it</div>
<div>
			(setq large-file-warning-threshold (* 1024 1024 1024))</div>
</blockquote>
<p>	这表示当文件&gt;1GB时才会提示&ldquo;文件太大&rdquo;的警告，不超过1GB的文件直接就打开了，不需要用户按 y 确认。</p>
<p>
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
		感谢关注我的微信公众号（微信扫一扫）：<br />
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
		以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 用JAVA程序读取本地的Hadoop sequence file</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 20 Apr 2023 12:23:18 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[Hadoop sequence file]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[本地]]></category>
		<category><![CDATA[读取]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13885</guid>

					<description><![CDATA[<div>
	Hadoop SequenceFile是Hadoop用于存储二进制键值对的文件格式。它支持存储不同的键值对类型,如:IntWritable/Text, NullWritable/BytesWritable等。</div>
<div>
	假设我的sequence file的key是BooleanWritable类型，value是Text类型，怎么读取它呢？<br />
	<span id="more-13885"></span></div>
<p>话不多说，直接上代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">&#160;&#160;&#160;&#160;Configuration&#160;conf&#160;=&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&#160;Configuration();
&#160;&#160;&#160;&#160;FileSystem&#160;fs&#160;=&#160;FileSystem.getLocal(conf);
&#160;&#160;&#160;&#160;Path&#160;seqFilePath&#160;=&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&#160;Path(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;/path/to/your/sequence-file&#34;</span>);

&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&#160;打印出sequence&#160;file的key和value的类型</span>
&#160;&#160;&#160;&#160;&#160;&#160;SequenceFile.Reader&#160;reader&#160;=&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&#160;SequenceFile.Reader(fs,&#160;seqFilePath,&#160;conf);
&#160;&#160;&#160;&#160;&#160;&#160;Writable&#160;key&#160;=&#160;(Writable)&#160;reader.getKeyClass().newInstance();
&#160;&#160;&#160;&#160;&#160;&#160;Writable&#160;value&#160;=&#160;(Writable)&#160;reader.getValueClass().newInstance();
&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&#160;(reader.next(key,&#160;value))&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;Key&#160;type:&#160;&#34;</span>&#160;+&#160;key.getClass());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;Value&#160;type:&#160;&#34;</span>&#160;+&#160;value.getClass());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">break</span>;
&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;reader.close();
&#160;&#160;&#160;&#160;}

&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&#160;打印出sequence&#160;file的内容</span>
&#160;&#160;&#160;&#160;&#160;&#160;SequenceFile.Reader&#160;reader&#160;=&#160;</code></pre>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<div>
	Hadoop SequenceFile是Hadoop用于存储二进制键值对的文件格式。它支持存储不同的键值对类型,如:IntWritable/Text, NullWritable/BytesWritable等。</div>
<div>
	假设我的sequence file的key是BooleanWritable类型，value是Text类型，怎么读取它呢？<br />
	<span id="more-13885"></span></div>
<p>话不多说，直接上代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">&nbsp;&nbsp;&nbsp;&nbsp;Configuration&nbsp;conf&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Configuration();
&nbsp;&nbsp;&nbsp;&nbsp;FileSystem&nbsp;fs&nbsp;=&nbsp;FileSystem.getLocal(conf);
&nbsp;&nbsp;&nbsp;&nbsp;Path&nbsp;seqFilePath&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Path(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;/path/to/your/sequence-file&quot;</span>);

&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;打印出sequence&nbsp;file的key和value的类型</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SequenceFile.Reader&nbsp;reader&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;SequenceFile.Reader(fs,&nbsp;seqFilePath,&nbsp;conf);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Writable&nbsp;key&nbsp;=&nbsp;(Writable)&nbsp;reader.getKeyClass().newInstance();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Writable&nbsp;value&nbsp;=&nbsp;(Writable)&nbsp;reader.getValueClass().newInstance();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&nbsp;(reader.next(key,&nbsp;value))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;Key&nbsp;type:&nbsp;&quot;</span>&nbsp;+&nbsp;key.getClass());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;Value&nbsp;type:&nbsp;&quot;</span>&nbsp;+&nbsp;value.getClass());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">break</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader.close();
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;打印出sequence&nbsp;file的内容</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SequenceFile.Reader&nbsp;reader&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;SequenceFile.Reader(fs,&nbsp;seqFilePath),&nbsp;conf);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BooleanWritable&nbsp;keyObj&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;BooleanWritable();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;valueObj&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Text();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&nbsp;(reader.next(keyObj,&nbsp;valueObj))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(keyObj.get()&nbsp;+&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;:&nbsp;&quot;</span>&nbsp;+&nbsp;valueObj);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader.close();
&nbsp;&nbsp;&nbsp;&nbsp;}
</code></pre>
</section>
<p>
输出类似于：</p>
<blockquote>
<div>
		Key type: class org.apache.hadoop.io.BooleanWritable</div>
<div>
		Value type: class org.apache.hadoop.io.Text<br />
		（文件内容此处省略）</div>
</blockquote>
<p>Maven依赖取决于你使用的Hadoop版本，下面是一个例子：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependencies</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>hadoop-common<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>3.2.1<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>hadoop-client<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>3.2.1<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>hadoop-hdfs<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>3.2.1<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependencies</span>&gt;</span></code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;关注不迷路&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;</p>
<p>
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] Apache Pig 加载/解析/读取 XML数据</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Wed, 18 Jan 2023 03:42:19 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[apache pig]]></category>
		<category><![CDATA[piggybank]]></category>
		<category><![CDATA[XMLLoader]]></category>
		<category><![CDATA[解析XML]]></category>
		<category><![CDATA[读取XML]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13817</guid>

					<description><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="XML logo" src="https://www.codelast.com/wp-content/uploads/ckfinder/images/xml.png" style="width: 200px; height: 200px;" /></div>
<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig加载/解析/读取XML数据不是一个常见的需求，但有时为了方便我们又不得不用，其实Pig的UDF库piggybank已经帮大家做好了这个工作了：只需要使用其中的<a href="https://pig.apache.org/docs/r0.17.0/api/org/apache/pig/piggybank/storage/XMLLoader.html" rel="noopener" target="_blank"><span style="background-color:#ffa07a;">XMLLoader</span></a>，就可以方便地实现XML文件解析。<br />
<span id="more-13817"></span><br />
假设有如下XML文件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">&#60;?xml&#160;version=&#34;1.0&#34;&#160;encoding=&#34;UTF-8&#34;?&#62;
</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&#62;</span>http://www.codelast.com/user/profile/159.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&#62;</span>159<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&#62;</span>李四<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&#62;</span>http://www.codelast.com/user/profile/220.html</code></pre>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="XML logo" src="https://www.codelast.com/wp-content/uploads/ckfinder/images/xml.png" style="width: 200px; height: 200px;" /></div>
<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig加载/解析/读取XML数据不是一个常见的需求，但有时为了方便我们又不得不用，其实Pig的UDF库piggybank已经帮大家做好了这个工作了：只需要使用其中的<a href="https://pig.apache.org/docs/r0.17.0/api/org/apache/pig/piggybank/storage/XMLLoader.html" rel="noopener" target="_blank"><span style="background-color:#ffa07a;">XMLLoader</span></a>，就可以方便地实现XML文件解析。<br />
<span id="more-13817"></span><br />
假设有如下XML文件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">&lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;UTF-8&quot;?&gt;
</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/159.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>159<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>李四<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/220.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>220<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>王五<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;
</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span></code></pre>
</section>
<p>首先我们欣赏一下这个XML文件，它用于存储多个用户的信息，&lt;users&gt;&lt;/users&gt; 标签把所有用户信息包裹在里面，&lt;user&gt;&lt;/user&gt; 标签则对应一个用户的信息。在每一个用户信息中，不仅有 profileUrl 这种第一层的属性，还有 data/id，data/name 这种更深层的属性，我们在下面的代码中，会把这些字段全部提取出来。<br />
这个XML虽然结构简单，但层次分明，通过解析这个XML文件，我们可以引申出对复杂XML文件的读取方法。<br />
这里需要特别说明一下，通常情况下存储在磁盘上的大数据都不会是这种&ldquo;格式化过&rdquo;的数据格式（为了方便大家观看，我把XML格式化成了上面的样子），而是一种紧凑的格式，例如可能是下面这个样子：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">&lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;UTF-8&quot;?&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/159.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>159<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>李四<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/220.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>220<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>王五<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span></code></pre>
</section>
<p>但是对piggybank的XMLLoader来说，上面的各种格式并不会影响它对XML内容的解析，这一点很好。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
话不多说，直接上代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">--&nbsp;注册piggybank的jar包，视实际情况修改此路径</span>
REGISTER&nbsp;/xxx/piggybank.jar;

DEFINE&nbsp;XPath&nbsp;org.apache.pig.piggybank.evaluation.xml.XPath();

A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;users.xml&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">USING</span>&nbsp;org.apache.pig.piggybank.storage.XMLLoader(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;user&#39;</span>)&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(x:&nbsp;chararray);
B&nbsp;=&nbsp;FOREACH&nbsp;A&nbsp;GENERATE&nbsp;XPath(x,&nbsp;&#39;user/profileUrl&#39;)&nbsp;AS&nbsp;profileUrl,&nbsp;XPath(x,&nbsp;&#39;user/data/id&#39;)&nbsp;AS&nbsp;id,&nbsp;XPath(x,&nbsp;&#39;user/data/name&#39;)&nbsp;AS&nbsp;name;
DUMP&nbsp;B;
</code></pre>
</section>
<p>代码解读：<br />
➤ XMLLoader 的参数&quot;user&quot;，应该是你的XML文件中，有多个标签的那个名字，例如，在上面的XML中，含有多个 user，但是只有一个 users，所以我们这里填的应该是 user<br />
➤ AS (x: chararray) 中的 &quot;x&quot; 其实可以是任意名称，我们下面只用这个名字来解析其下的字段，所以这个名字不重要。<br />
➤ 在 XPath() 中我们可以通过XML的层级关系来取出指定的字段，一看就明白。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
上面的代码输出：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">(http:<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//www.codelast.com/user/profile/159.html,159,李四)</span>
(http:<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//www.codelast.com/user/profile/220.html,220,王五)</span></code></pre>
</section>
<p>也就是我们提取的3个字段。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 通过第三方工具/JAVA程序访问S3存储</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 14 Nov 2022 16:32:43 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[s3-command-line]]></category>
		<category><![CDATA[对象存储]]></category>
		<category><![CDATA[访问]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13652</guid>

					<description><![CDATA[<p>S3是亚马逊2006年推出的简单存储服务（Simple Storage Service），理论上是一个全球存储区域网络，你可以把它想像成一个超大的硬盘，可以在其中存储和检索数字资产，通过 S3 存储和检索的资产被称为对象，对象存储在存储段（bucket）中。<br />
很多公司都推出了自己的对象存储服务，例如阿里云对象存储服务OSS，可以使用S3 API进行访问。<br />
<span id="more-13652"></span><br />
话不多说，我们看看如何读写S3。<br />
<span style="color:#ff0000;">➤</span> 通过第三方工具<br />
这种工具很多，<a href="https://github.com/lpflpf/s3-command-line" rel="noopener" target="_blank">s3-command-line</a>&#160;就是一个。这是一个GoLang开发的命令行工具，编译出来只有13MB。它支持文件的上传、下载、删除、列表，已经满足了大多数使用场景需求。<br />
checkout它的源码，在安装有Go语言环境的服务器上执行 go build&#160;即可编译出可执行程序 s3-command-line，这个只需要做一次，最终运行 s3-command-line&#160;软件的服务器上并不需要安装GoLang环境。<br />
在使用 s3-command-line&#160;之前，我们需要创建一个配置文件 <span style="color:#0000ff;">config.json</span>，填入我们访问S3所需的密钥等信息：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="json language-json hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">{
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;id&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;...&#34;</span>,
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;secret&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;...&#34;</span>,
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;endPoint&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;http://...&#34;</span>,
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;region&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;...&#34;</span></code></pre>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<p>S3是亚马逊2006年推出的简单存储服务（Simple Storage Service），理论上是一个全球存储区域网络，你可以把它想像成一个超大的硬盘，可以在其中存储和检索数字资产，通过 S3 存储和检索的资产被称为对象，对象存储在存储段（bucket）中。<br />
很多公司都推出了自己的对象存储服务，例如阿里云对象存储服务OSS，可以使用S3 API进行访问。<br />
<span id="more-13652"></span><br />
话不多说，我们看看如何读写S3。<br />
<span style="color:#ff0000;">➤</span> 通过第三方工具<br />
这种工具很多，<a href="https://github.com/lpflpf/s3-command-line" rel="noopener" target="_blank">s3-command-line</a>&nbsp;就是一个。这是一个GoLang开发的命令行工具，编译出来只有13MB。它支持文件的上传、下载、删除、列表，已经满足了大多数使用场景需求。<br />
checkout它的源码，在安装有Go语言环境的服务器上执行 go build&nbsp;即可编译出可执行程序 s3-command-line，这个只需要做一次，最终运行 s3-command-line&nbsp;软件的服务器上并不需要安装GoLang环境。<br />
在使用 s3-command-line&nbsp;之前，我们需要创建一个配置文件 <span style="color:#0000ff;">config.json</span>，填入我们访问S3所需的密钥等信息：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="json language-json hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">{
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;id&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;...&quot;</span>,
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;secret&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;...&quot;</span>,
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;endPoint&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;http://...&quot;</span>,
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;region&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;...&quot;</span>
}
</code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
这些信息你可以在你使用的S3平台上找到。<br />
假设我们要读写的bucket名为 <span style="color:#0000ff;">my-bucket</span>，那么下面的命令会告诉你怎么使用 s3-command-line：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">列出指定&nbsp;bucket&nbsp;里的文件：
./s3-command-line&nbsp;ls&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;/

从指定的&nbsp;bucket&nbsp;删除文件&nbsp;1.txt：
./s3-command-line&nbsp;rm&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;1.txt

上传本地文件&nbsp;1.txt&nbsp;到指定的&nbsp;bucket：
./s3-command-line&nbsp;put&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;1.txt

从指定的&nbsp;bucket&nbsp;下载文件&nbsp;1.txt&nbsp;到本地：
./s3-command-line&nbsp;get&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;1.txt
</code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
总结：简单好用，编译成可执行程序后没有对其他library的依赖，令人舒适。</p>
<p><span style="color: rgb(255, 0, 0);">➤</span>&nbsp;自己写JAVA程序<br />
JDK版本：1.8.0_221，Maven：3.6.3<br />
首先你需要在 pom.xml&nbsp;中添加相关依赖（参考<a href="https://github.com/aws/aws-sdk-java-v2/#using-the-sdk" rel="noopener" target="_blank">这里</a>）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>software.amazon.awssdk<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>aws-sdk-java<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>2.18.16<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span></code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
然后就可以开始写代码了（测试可用）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">package</span>&nbsp;com.codelast;


<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;lombok.extern.slf4j.Slf4j;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.apache.commons.lang.StringUtils;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.kohsuke.args4j.CmdLineException;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.kohsuke.args4j.CmdLineParser;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.kohsuke.args4j.Option;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.core.sync.RequestBody;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.regions.Region;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.S3Client;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.PutObjectRequest;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.PutObjectResponse;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.S3Exception;

<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.io.File;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.io.FileInputStream;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.io.IOException;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.net.URI;

<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">/**
&nbsp;*&nbsp;S3存储操作类。
&nbsp;*&nbsp;参考：https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/s3/src/main/java/com/example/s3/PutObject.java
&nbsp;*
&nbsp;*&nbsp;<span class="hljs-doctag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">@author</span>&nbsp;DarranZhang@codelast.com
&nbsp;*&nbsp;<span class="hljs-doctag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">@version</span>&nbsp;2022-11-14
&nbsp;*/
</span>
<span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">@Slf</span>4j
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-class" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">class</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">S3Operator</span>&nbsp;</span>{
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;ACCESS_KEY&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_key&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;SECRET_KEY&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_secret&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;END_POINT&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;http://your_end_point_url&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;REGION&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_region&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;BUCKET_NAME&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_bucket_name&quot;</span>;

&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-class" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">class</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">Options</span>&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">@Option</span>(name&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;--localFile&quot;</span>,&nbsp;usage&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;the&nbsp;path&nbsp;of&nbsp;the&nbsp;local&nbsp;file&nbsp;to&nbsp;upload&nbsp;to&nbsp;S3&quot;</span>,&nbsp;required&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">true</span>)
&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;localFile;
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">main</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(String[]&nbsp;args)</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">throws</span>&nbsp;Exception&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;Options&nbsp;opts&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Options();
&nbsp;&nbsp;&nbsp;&nbsp;CmdLineParser&nbsp;parser&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;CmdLineParser(opts);
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parser.parseArgument(args);
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(CmdLineException&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.error(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;command&nbsp;parse&nbsp;fail&quot;</span>,&nbsp;e);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.exit(<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">1</span>);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;S3Operator&nbsp;operator&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;S3Operator();
&nbsp;&nbsp;&nbsp;&nbsp;operator.upload(opts.localFile);
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">upload</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(String&nbsp;localFile)</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">throws</span>&nbsp;Exception&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;AwsBasicCredentials&nbsp;credentials&nbsp;=&nbsp;AwsBasicCredentials.create(ACCESS_KEY,&nbsp;SECRET_KEY);
&nbsp;&nbsp;&nbsp;&nbsp;Region&nbsp;region&nbsp;=&nbsp;Region.of(REGION);
&nbsp;&nbsp;&nbsp;&nbsp;S3Client&nbsp;s3Client&nbsp;=&nbsp;S3Client.builder()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.endpointOverride(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;URI(END_POINT))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.region(region)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.credentialsProvider(StaticCredentialsProvider.create(credentials))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.build();

&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;s3FileName&nbsp;=&nbsp;StringUtils.substringAfterLast(localFile,&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;/&quot;</span>);&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;上传到S3之后的文件名，不一定要和本地文件名一致，但为了直观，这里保持一致</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">if</span>&nbsp;(StringUtils.isEmpty(s3FileName))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;msg&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;local&nbsp;file&nbsp;name&nbsp;is&nbsp;empty&quot;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.error(msg);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">throw</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;RuntimeException(msg);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;每次上传前，不用先删除再上传，因为最新上传的同名文件会覆盖之前的文件</span>
&nbsp;&nbsp;&nbsp;&nbsp;putObject(s3Client,&nbsp;BUCKET_NAME,&nbsp;s3FileName,&nbsp;localFile);
&nbsp;&nbsp;&nbsp;&nbsp;s3Client.close();
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">putObject</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(S3Client&nbsp;s3Client,&nbsp;String&nbsp;bucketName,&nbsp;String&nbsp;objectKey,&nbsp;String&nbsp;objectPath)</span>&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PutObjectRequest&nbsp;request&nbsp;=&nbsp;PutObjectRequest.builder().bucket(bucketName).key(objectKey).build();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PutObjectResponse&nbsp;response&nbsp;=&nbsp;s3Client.putObject(request,&nbsp;RequestBody.fromBytes(getObjectFile(objectPath)));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;successfully&nbsp;upload&nbsp;file&nbsp;[{}]&nbsp;to&nbsp;S3,&nbsp;entity&nbsp;tag:&nbsp;[{}]&quot;</span>,&nbsp;objectPath,&nbsp;response.eTag());
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(S3Exception&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.error(String.format(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;failed&nbsp;to&nbsp;upload&nbsp;file&nbsp;[%s]&nbsp;to&nbsp;S3&quot;</span>,&nbsp;objectPath),&nbsp;e);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">byte</span>[]&nbsp;getObjectFile(String&nbsp;filePath)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fileInputStream&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">null</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">byte</span>[]&nbsp;bytesArray&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">null</span>;

&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;file&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;File(filePath);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bytesArray&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">byte</span>[(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">int</span>)&nbsp;file.length()];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileInputStream&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;FileInputStream(file);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileInputStream.read(bytesArray);
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(IOException&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">finally</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">if</span>&nbsp;(fileInputStream&nbsp;!=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">null</span>)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileInputStream.close();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(IOException&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">return</span>&nbsp;bytesArray;
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">deleteObject</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(S3Client&nbsp;s3,&nbsp;String&nbsp;bucket,&nbsp;String&nbsp;s3FileName)</span>&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;DeleteObjectRequest&nbsp;request&nbsp;=&nbsp;DeleteObjectRequest.builder().bucket(bucket).key(s3FileName).build();
&nbsp;&nbsp;&nbsp;&nbsp;s3.deleteObject(request);
&nbsp;&nbsp;}
}
</code></pre>
</section>
<p> 这样我们就实现了用JAVA访问S3，不过，如果你仔细看会发现，当引入S3的依赖后，你的项目编译出的 fat jar&nbsp;体积剧增了400MB左右！这也太恶心了...<br />
当然，上面引入的 whole-SDK 依赖，是我为了省事引入了所有S3相关的模块，或许你有些用不到的模块，可以不用引入 whole-SDK，而是分别引入单独的模块，但我有空去想这些玩意的话，还不如使用 s3-command-line&nbsp;简单呢，不是吗？毕竟时间就是生命，别在这些无聊的事上浪费生命。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;总结<br />
如果你操作S3时只使用上传、下载、删除、列表功能，那么建议不要自己写代码，使用 s3-command-line&nbsp;更香。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] Apache Pig如何按数据分组保存到不同的子目录中(MultiStorage)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 06 Nov 2022 06:30:06 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[apache pig]]></category>
		<category><![CDATA[MultiStorage]]></category>
		<category><![CDATA[多目录]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13628</guid>

					<description><![CDATA[<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig进行数据处理的时候，我们通常会在最后把处理结果保存到一个HDFS目录下：</p>
<blockquote>
<p>
		STORE result INTO &#39;/my_output_dir&#39;;</p>
</blockquote>
<p>这是最常见的情况。<br />
但是，如果我们想根据某个字段，把数据分成多组，分别存储在多个目录下呢？举个可能不恰当的例子，就有点像我们先把数据按某个字段分组：</p>
<blockquote>
<p>
		GROUP data BY field;</p>
</blockquote>
<p>再把各个group的数据分别存储在不同的目录下一样。<br />
<span id="more-13628"></span><br />
现在来看一个实例。<br />
假设有如下数据（用 tab&#160;分隔的四列分别为：人员类型的id，人员类型的描述，姓名，爱好）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<table style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; width: 100%;">
<thead style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				type</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				desc</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				name</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				hobby</th>
</tr>
</thead>
<tbody style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				陈玉</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				篮球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				3</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				老师</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				王强</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				足球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				许勤</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				下棋</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				范雨</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				跑步</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				李林</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				游泳</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				涂欣</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				看书</td>
</tr>
</tbody>
</table>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig进行数据处理的时候，我们通常会在最后把处理结果保存到一个HDFS目录下：</p>
<blockquote>
<p>
		STORE result INTO &#39;/my_output_dir&#39;;</p>
</blockquote>
<p>这是最常见的情况。<br />
但是，如果我们想根据某个字段，把数据分成多组，分别存储在多个目录下呢？举个可能不恰当的例子，就有点像我们先把数据按某个字段分组：</p>
<blockquote>
<p>
		GROUP data BY field;</p>
</blockquote>
<p>再把各个group的数据分别存储在不同的目录下一样。<br />
<span id="more-13628"></span><br />
现在来看一个实例。<br />
假设有如下数据（用 tab&nbsp;分隔的四列分别为：人员类型的id，人员类型的描述，姓名，爱好）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<table style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; width: 100%;">
<thead style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				type</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				desc</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				name</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				hobby</th>
</tr>
</thead>
<tbody style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				陈玉</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				篮球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				3</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				老师</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				王强</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				足球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				许勤</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				下棋</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				范雨</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				跑步</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				李林</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				游泳</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				涂欣</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				看书</td>
</tr>
</tbody>
</table>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
现在我们想按第1列 type，把这份数据处理之后分别存储到不同的目录下，即 type 2（学生）的数据保存到目录&quot;2&quot;里，type 3（老师）的数据保存到目录&quot;3&quot;里，依此类推。<br />
一个最简单也最笨的方法是： 在Pig中把数据 SPLIT(拆分) 成多份，再分别 STORE(存储) 到指定的目录下：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">type</span>:&nbsp;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">int</span>,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">desc</span>:&nbsp;chararray,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>:&nbsp;chararray,&nbsp;hobby:&nbsp;chararray);
SPLIT&nbsp;A&nbsp;INTO&nbsp;A1&nbsp;IF&nbsp;(type&nbsp;==&nbsp;1),&nbsp;A2&nbsp;IF&nbsp;(type&nbsp;==&nbsp;2),&nbsp;A3&nbsp;IF&nbsp;(type&nbsp;==&nbsp;3);

STORE&nbsp;A1&nbsp;INTO&nbsp;&#39;/my_output_dir/1&#39;;
STORE&nbsp;A2&nbsp;INTO&nbsp;&#39;/my_output_dir/2&#39;;
STORE&nbsp;A3&nbsp;INTO&nbsp;&#39;/my_output_dir/3&#39;;
</code></pre>
</section>
<p>
代码很直观，但当 type 有太多种数值的时候，比如说type有100种数值，难道你打算写100个 STORE 语句吗？会疯。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
更好的办法是利用piggybank里的一个UDF <a href="https://pig.apache.org/docs/latest/api/org/apache/pig/piggybank/storage/MultiStorage.html" rel="noopener" target="_blank">MultiStorage</a>来实现同样的功能：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">type</span>:&nbsp;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">int</span>,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">desc</span>:&nbsp;chararray,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>:&nbsp;chararray,&nbsp;hobby:&nbsp;chararray);
STORE&nbsp;A&nbsp;INTO&nbsp;&#39;/my_output_dir&#39;&nbsp;USING&nbsp;org.apache.pig.piggybank.storage.MultiStorage(&#39;/my_output_dir&#39;,&nbsp;&#39;0&#39;,&nbsp;&#39;none&#39;,&nbsp;&#39;\t&#39;,&nbsp;&#39;true&#39;);
</code></pre>
</section>
<p>看，只要一行代码就代替了无数的 SPLIT INTO&nbsp;以及 STORE INTO&nbsp;语句，多么优雅。<br />
MultiStorage的参数含义分别是：</p>
<blockquote>
<p>
		public MultiStorage(String <span style="color:#0000ff;">parentPathStr</span>, String <span style="color:#0000ff;">splitFieldIndex</span>, String <span style="color:#0000ff;">compression</span>, String <span style="color:#0000ff;">fieldDel</span>, String <span style="color:#0000ff;">isRemoveKeys</span>)</p>
</blockquote>
<p>parentPathStr：输出文件的父目录。事实上这个参数不起作用，真正起作用的输出路径是在 &quot;INTO&quot;&nbsp;关键字后面的那个路径里指定的，但开发团队为了向前兼容，保留了这个参数，因此，把这个参数里的路径，设置成和 &quot;INTO&quot;&nbsp;后面的路径一样即可。<br />
splitFieldIndex：使用数据里的第几个字段来拆分数据存储到不同的子目录下（从0开始）。我这里设置成0，是表示我使用数据里的 type&nbsp;字段来拆分数据。<br />
compression：输出数据的压缩方式，可以是&nbsp;&#39;bz2&#39;，&#39;bz&#39;，&#39;gz&#39;，&#39;none&#39;这几种取值，其中 none&nbsp;表示无压缩。<br />
fieldDel：输出数据多个字段的分隔符。<br />
isRemoveKeys：输出数据是否移除掉用于拆分数据的字段。我这里设置成 true&nbsp;表示在输出数据中不会包含 type，因为我只想拿 type&nbsp;用作输出子目录名，不想让它出现在输出数据中。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
最后我们看一下执行结果。生成了3个目录，每个 type&nbsp;一个目录：</p>
<blockquote>
<p>
		/my_output_dir/1<br />
		/my_output_dir/2<br />
		/my_output_dir/3<br />
		/my_output_dir/_SUCCESS</p>
</blockquote>
<p>再来看一下子目录&quot;1&quot;里的文件：</p>
<blockquote>
<p>
		/my_output_dir/1/1-0,000</p>
</blockquote>
<p>其文件内容是：</p>
<blockquote>
<p>
		保安&nbsp; &nbsp; 许勤&nbsp; &nbsp; 下棋<br />
		保安&nbsp; &nbsp; 涂欣&nbsp; &nbsp; 看书</p>
</blockquote>
<p>这里面全是 type 1&nbsp;的数据。可见 MultiStorage 确实把数据按照 type&nbsp;拆分并存储在了不同的子目录下。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 用Charles Proxy来抓包Chrome浏览器的数据</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Fri, 18 Feb 2022 09:17:18 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Charles Proxy]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[抓包]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13530</guid>

					<description><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="charles proxy" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy.png" style="width: 571px; height: 221px;" /></div>
<p>查看Charles Proxy文章合集，请点击<a href="https://www.codelast.com/?p=13742" target="_blank" rel="noopener">这里</a>。<br />
本文适用的操作系统：Ubuntu</p>
<blockquote>
<p>
		Charles Proxy是一个HTTP代理/HTTP监视器/反向代理，它使开发人员能够查看其计算机和Internet之间的所有HTTP和SSL/HTTPS流量。这包括请求、响应和HTTP headers（其中包含cookie和缓存信息）。</p>
</blockquote>
<p>在Chrome浏览器中把代理服务器设置成<a href="https://www.charlesproxy.com/" rel="noopener" target="_blank">Charles Proxy</a>在本地提供的代理，可以让Charles Proxy把Chrome的网络流量抓取下来。<br />
配置方法如下。<br />
<span id="more-13530"></span><br />
<span style="color:#0000ff;">➤</span> Charles Proxy端的配置<br />
<span style="color:#ff0000;">✔</span> Proxy&#8594;Proxy Settings：<br />
<img decoding="async" alt="charles proxy settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy_settings.png" style="width: 500px; height: 492px;" /><br />
Charles Proxy软件打开后，会启动一个代理服务器，在这里你可以修改代理服务器的端口等信息，通常来说保持默认参数即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">✔</span>&#160;Proxy&#8594;SSL Proxying Settings：<br />
<img decoding="async" alt="charles ssl proxying settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_ssl_proxying_settings.png" style="width: 450px; height: 411px;" /><br />
勾选上&#8220;Enable SSL Proxying&#8221;，这样可以对https的流量进行抓包。<br />
并且在&#8220;Location&#8221;里设置你感兴趣的域名，注意：只有这些域名的流量会被抓包。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">✔</span>&#160;导出Charles Proxy的证书<br />
在Charles界面上点击菜单导出 .pem 证书：</p>
<blockquote>
<p>
		Help&#8594;SSL Proxying&#8594;Save Charles Root Certificate</p>
</blockquote>
<p>把文件保存到 ~/charles.pem&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="charles proxy" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy.png" style="width: 571px; height: 221px;" /></div>
<p>查看Charles Proxy文章合集，请点击<a href="https://www.codelast.com/?p=13742" target="_blank" rel="noopener">这里</a>。<br />
本文适用的操作系统：Ubuntu</p>
<blockquote>
<p>
		Charles Proxy是一个HTTP代理/HTTP监视器/反向代理，它使开发人员能够查看其计算机和Internet之间的所有HTTP和SSL/HTTPS流量。这包括请求、响应和HTTP headers（其中包含cookie和缓存信息）。</p>
</blockquote>
<p>在Chrome浏览器中把代理服务器设置成<a href="https://www.charlesproxy.com/" rel="noopener" target="_blank">Charles Proxy</a>在本地提供的代理，可以让Charles Proxy把Chrome的网络流量抓取下来。<br />
配置方法如下。<br />
<span id="more-13530"></span><br />
<span style="color:#0000ff;">➤</span> Charles Proxy端的配置<br />
<span style="color:#ff0000;"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span> Proxy&rarr;Proxy Settings：<br />
<img decoding="async" alt="charles proxy settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy_settings.png" style="width: 500px; height: 492px;" /><br />
Charles Proxy软件打开后，会启动一个代理服务器，在这里你可以修改代理服务器的端口等信息，通常来说保持默认参数即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;Proxy&rarr;SSL Proxying Settings：<br />
<img decoding="async" alt="charles ssl proxying settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_ssl_proxying_settings.png" style="width: 450px; height: 411px;" /><br />
勾选上&ldquo;Enable SSL Proxying&rdquo;，这样可以对https的流量进行抓包。<br />
并且在&ldquo;Location&rdquo;里设置你感兴趣的域名，注意：只有这些域名的流量会被抓包。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;导出Charles Proxy的证书<br />
在Charles界面上点击菜单导出 .pem 证书：</p>
<blockquote>
<p>
		Help&rarr;SSL Proxying&rarr;Save Charles Root Certificate</p>
</blockquote>
<p>把文件保存到 ~/charles.pem<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(0, 0, 255);">➤</span>&nbsp;Chrome浏览器端的配置（以Ubuntu系统上的Chrome为例）<br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;把证书导入Chrome<br />
依次打开Chrome的如下页面：<br />
&ldquo;<span style="color: rgb(0, 0, 255);">设置</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(0, 0, 255);">安全和隐私设置</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(0, 0, 255);">安全</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(255, 0, 0);">管理证书</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(255, 0, 0);">授权机构</span>&rdquo;：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/import_charles_proxy_ca_1.png" style="width: 668px; height: 182px;" /><br />
点击&ldquo;<span style="color:#0000ff;">导入</span>&rdquo;按钮，选择刚才生成的 .pem 证书文件，会弹出下面的对话框：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/import_charles_proxy_ca_2.png" style="width: 507px; height: 297px;" /><br />
勾选第一项。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;配置Chrome的代理<br />
使用Chrome的SwitchyOmega插件，添加一个名为&ldquo;Charles Proxy&rdquo;的情景模式：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy_config_in_SwitchyOmega.png" style="width: 600px; height: 266px;" /><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(0, 0, 255);">➤</span>&nbsp;测试<br />
在Chrome的SwitchyOmega插件中选择刚配置好的Charles Proxy情景模式，再访问一个前面设置好的感兴趣的域名下的网页。<br />
在导入证书之前，会发现抓不了：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/before_trust_charles_proxy_ca.png" style="width: 600px; height: 74px;" /><br />
&mdash;&mdash;界面上全是红叉，以及 Failed。</p>
<p>在导入了证书之后，再试一次，会发现抓包可以成功完成：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/after_trust_charles_proxy_ca.png" style="width: 821px; height: 117px;" /><br />
&mdash;&mdash;状态码是200，以及Status是Complete，这说明一切正常。</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：<br />
<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 使用Selenium Wire访问网站时提示&quot;您与此网站之间建立的连接不安全&quot;的解决办法</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 12:46:31 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Selenium Wire]]></category>
		<category><![CDATA[信任]]></category>
		<category><![CDATA[安全]]></category>
		<category><![CDATA[证书]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13517</guid>

					<description><![CDATA[<p>本文针对的操作系统：Ubuntu / MacOS</p>
<p>这个问题是由于<span style="background-color: rgb(255, 255, 255); font-family: &#34;JetBrains Mono&#34;, &#34;Droid Sans Mono&#34;, &#34;monospace&#34;, monospace; font-size: 16px; white-space: pre;">Selenium Wire</span>使用了自己的证书来访问网站，而它的证书默认不受Chrome信任。<br />
在Chrome里查看证书可以看到：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/selenium_wire_ca_info.png" style="width: 263px; height: 107px;" /></a><br />
<span id="more-13517"></span><br />
解决办法：<br />
➤ 导出<span style="font-family: &#34;JetBrains Mono&#34;, &#34;Droid Sans Mono&#34;, &#34;monospace&#34;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的</span>证书文件<br />
在安装<span style="font-family: &#34;JetBrains Mono&#34;, &#34;Droid Sans Mono&#34;, &#34;monospace&#34;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的Python环境里执行：</span></p>
<blockquote>
<p>
		python -m seleniumwire extractcert</p>
</blockquote>
<p>成功的话，会在当前目录下生成 ca.crt 证书文件。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
➤ 把证书导入Chrome<br />
✔ 对Ubuntu系统（其他Linux发行版应该类似，我没有用过），依次打开Chrome的如下页面（以下操作过程都在Chrome浏览器内部完成，不会跳转到操作系统的任何设置对话框里）：<br />
&#8220;<span style="color:#0000ff;">设置</span>&#8221;&#8594;&#8220;<span style="color:#0000ff;">安全和隐私设置</span>&#8221;&#8594;&#8220;<span style="color:#0000ff;">安全</span>&#8221;&#8594;&#8220;<span style="color:#ff0000;">管理证书</span>&#8221;&#8594;&#8220;<span style="color:#ff0000;">授权机构</span>&#8221;<br />
点击&#8220;导入&#8221;按钮，选择刚才生成的证书文件，会弹出下面的对话框：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/chrome_ca_auth_center.png" style="width: 518px; height: 311px;" /><br />
只勾选红框的那一项再点击&#8220;确定&#8221;即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>本文针对的操作系统：Ubuntu / MacOS</p>
<p>这个问题是由于<span style="background-color: rgb(255, 255, 255); font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre;">Selenium Wire</span>使用了自己的证书来访问网站，而它的证书默认不受Chrome信任。<br />
在Chrome里查看证书可以看到：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/selenium_wire_ca_info.png" style="width: 263px; height: 107px;" /></a><br />
<span id="more-13517"></span><br />
解决办法：<br />
➤ 导出<span style="font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的</span>证书文件<br />
在安装<span style="font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的Python环境里执行：</span></p>
<blockquote>
<p>
		python -m seleniumwire extractcert</p>
</blockquote>
<p>成功的话，会在当前目录下生成 ca.crt 证书文件。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
➤ 把证书导入Chrome<br />
<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 对Ubuntu系统（其他Linux发行版应该类似，我没有用过），依次打开Chrome的如下页面（以下操作过程都在Chrome浏览器内部完成，不会跳转到操作系统的任何设置对话框里）：<br />
&ldquo;<span style="color:#0000ff;">设置</span>&rdquo;&rarr;&ldquo;<span style="color:#0000ff;">安全和隐私设置</span>&rdquo;&rarr;&ldquo;<span style="color:#0000ff;">安全</span>&rdquo;&rarr;&ldquo;<span style="color:#ff0000;">管理证书</span>&rdquo;&rarr;&ldquo;<span style="color:#ff0000;">授权机构</span>&rdquo;<br />
点击&ldquo;导入&rdquo;按钮，选择刚才生成的证书文件，会弹出下面的对话框：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/chrome_ca_auth_center.png" style="width: 518px; height: 311px;" /><br />
只勾选红框的那一项再点击&ldquo;确定&rdquo;即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" />&nbsp;对MacOS，当你按照上面的步骤点击了&ldquo;<span style="color: rgb(255, 0, 0);">管理证书</span>&rdquo;时，会发现Mac自动打开了系统的&ldquo;钥匙串访问&rdquo;设置对话框，也就是说你不能像在Ubuntu系统里一样只在Chrome里就能设置好。<br />
此时，按照如下步骤去设置：<br />
把前面生成的 ca.crt&nbsp;文件拖入&ldquo;钥匙串访问&rdquo;对话框，会要你输入密码把Selenium Wire的证书导入，之后就会看到导入的证书不被信任：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_untrusted_1.png" style="width: 600px; height: 344px;" /></p>
<p>双击它也会进一步看到不被信任：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_untrusted_2.png" style="width: 500px; height: 361px;" /></p>
<p>展开&ldquo;信任&rdquo;前的箭头，把&ldquo;使用此证书时&rdquo;改成&ldquo;始终信任&rdquo;：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_trusted_1.png" style="width: 400px; height: 448px;" /></p>
<p>关闭对话框，会要求你输入密码确认，之后就会看到证书已被信任：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_trusted_2.png" style="width: 600px; height: 376px;" /></p>
<p>现在再试试，<span style="font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire不会再出现之前的不安全提示啦。</span><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：<br />
<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 扩展VirtualBox虚拟机的磁盘空间(vdi文件)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 18 Oct 2021 18:14:03 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[GParted]]></category>
		<category><![CDATA[vdi]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[扩展空间]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13346</guid>

					<description><![CDATA[<p>宿主机：Ubuntu 16.04 LTS<br />
虚拟机：Windows 10</p>
<p>VirtualBox虚拟机文件有很多种格式，我的是vdi格式，对应的磁盘空间是37GB（Win10系统里只有一个C盘），由于虚拟机里的空间不够用了，想把它扩展成45GB，并且在数据不丢失的情况下仍然保持&#8220;只有一个C盘&#8221;的状态。<br />
下面是操作方法。<br />
<span id="more-13346"></span><br />
<span style="color:#ff0000;">➤</span> 扩大vdi空间<br />
在宿主机的命令行执行命令：</p>
<blockquote>
<div>
		[codelast@ win10.new]$ <span style="color:#0000ff;">sudo VBoxManage modifyhd win10.vdi --resize 46080</span></div>
<div>
		0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%</div>
</blockquote>
<div>
	其中，46080 的单位是MB。这样，vdi 文件对应的虚拟机的磁盘空间就被扩展成了 45GB，但是从 37GB&#160;&#8594; 45GB，多出来的 8GB <span style="color:#ff0000;">仍然是不可用的</span>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	我们可以进入虚拟机的系统验证这一点。在虚拟机里用快捷键 Win+R 打开运行命令对话框，输入&#160;<span style="color:#0000ff;">diskmgmt.msc</span> 并回车，会打开Windows的&#8220;磁盘管理&#8221;软件，在里面我们会看到：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_01.png" style="width: 750px; height: 569px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	可见那8GB是&#8220;未分配&#8221;状态，如果要把它合并到原先的37GB里，并且不破坏已安装好的Win10的话，需要用GParted软件来合并扩展空间（如果你不需要合并在一起，只需要把新增的8GB创建成另一个分区，那么就简单得多，不需要用本文的方法）。
<p>	首先到<a href="https://gparted.org/" rel="noopener" target="_blank"><span style="background-color:#faebd7;">GParted官网</span></a>下载GParted ISO镜像文件（gparted-xxx.iso）。</p></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>宿主机：Ubuntu 16.04 LTS<br />
虚拟机：Windows 10</p>
<p>VirtualBox虚拟机文件有很多种格式，我的是vdi格式，对应的磁盘空间是37GB（Win10系统里只有一个C盘），由于虚拟机里的空间不够用了，想把它扩展成45GB，并且在数据不丢失的情况下仍然保持&ldquo;只有一个C盘&rdquo;的状态。<br />
下面是操作方法。<br />
<span id="more-13346"></span><br />
<span style="color:#ff0000;">➤</span> 扩大vdi空间<br />
在宿主机的命令行执行命令：</p>
<blockquote>
<div>
		[codelast@ win10.new]$ <span style="color:#0000ff;">sudo VBoxManage modifyhd win10.vdi --resize 46080</span></div>
<div>
		0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%</div>
</blockquote>
<div>
	其中，46080 的单位是MB。这样，vdi 文件对应的虚拟机的磁盘空间就被扩展成了 45GB，但是从 37GB&nbsp;&rarr; 45GB，多出来的 8GB <span style="color:#ff0000;">仍然是不可用的</span>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	我们可以进入虚拟机的系统验证这一点。在虚拟机里用快捷键 Win+R 打开运行命令对话框，输入&nbsp;<span style="color:#0000ff;">diskmgmt.msc</span> 并回车，会打开Windows的&ldquo;磁盘管理&rdquo;软件，在里面我们会看到：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_01.png" style="width: 750px; height: 569px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	可见那8GB是&ldquo;未分配&rdquo;状态，如果要把它合并到原先的37GB里，并且不破坏已安装好的Win10的话，需要用GParted软件来合并扩展空间（如果你不需要合并在一起，只需要把新增的8GB创建成另一个分区，那么就简单得多，不需要用本文的方法）。</p>
<p>	首先到<a href="https://gparted.org/" rel="noopener" target="_blank"><span style="background-color:#faebd7;">GParted官网</span></a>下载GParted ISO镜像文件（gparted-xxx.iso）。<br />
	<span style="color:#ff0000;">➤</span> 把GParted ISO以光盘的形式挂载到虚拟机系统上<br />
	打开VirtualBox，在该虚拟机的&ldquo;存储&rdquo;设置页面上，你会看到一个 *.vdi&nbsp;的虚拟机文件，对应的就是虚拟机里看到的磁盘：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_02.png" style="width: 670px; height: 573px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	点击&ldquo;控制器: SATA&rdquo;右侧的光盘加号按钮，弹出下面的对话框：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_03.png" style="width: 640px; height: 388px;" /></a><br />
	点击左上方的&ldquo;注册&rdquo;按钮选择本地磁盘上的GParted ISO文件，会像上图一样显示在列表中。<br />
	继续点击&ldquo;选择&rdquo;按钮，会看到ISO已经成功挂载了：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_04.png" style="width: 670px; height: 573px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;重启虚拟机进入GParted软件<br />
	在虚拟机的&ldquo;系统&rdquo;设置页面上，把&ldquo;光驱&rdquo;调整成启动顺序的第一项：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_05.png" style="width: 670px; height: 573px;" /></a><br />
	这样开机才能先打开GParted，而不是进入安装过的那个Windows系统。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	设置好后重启虚拟机，可以成功进入GParted：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_06.jpg" style="width: 670px; height: 573px;" /></a><br />
	回车进入列表的第一项。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;使用GParted调整分区大小<br />
	打开GParted，在其界面上可看到 8GB&nbsp;的未分配空间：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_07.png" style="width: 770px; height: 517px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	选中 /dev/sda1&nbsp;那个需要扩大的分区，点击工具栏的&ldquo;Resize/Move&rdquo;按钮，会弹出一个对话框：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_08.png" style="width: 773px; height: 518px;" /></a><br />
	你不需要输入具体的数值，只需要用鼠标拖拽绿色方框的右边，把它拉到最右，就可以把空间扩到最大。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	点击&ldquo;Resize/Move&rdquo;按钮会看到空间已经被扩大了：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_09.png" style="width: 772px; height: 517px;" /></a><br />
	但是注意：现在只是临时状态，必须要点击工具栏上的&ldquo;应用&rdquo;按钮，才能真正让扩大分区的操作开始执行：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_10.png" style="width: 771px; height: 517px;" /></a><br />
	待操作完成后，Windows C盘就成功地从37GB变成了45GB，并且C盘上原来的数据不会丢失。</p>
<p>	<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;验证结果<br />
	在虚拟机设置中，把光驱从启动项中移除（防止再次进入GParted），再重启虚拟机，查看Windows系统的C盘大小，就会发现成功了：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_11.png" style="width: 264px; height: 74px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
<p>
	&nbsp;</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
