HTTP.UTF_8过时

今天发现项目里org.apache.http.protocol包下的HTTP.UTF_8过时了,而在HTTP里没找到UTF-8的替代品

结果从网络搜索发现可以用这个替代:StandardCharsets.UTF_8

这个类在java.nio.charset下

本人机器jdk版本1.8

def inject_new_data(self) -> bool: try: full_content = self.c_file_path.read_text(encoding='utf-8') except Exception as e: self.logger.error(f"读取主 C 文件失败: {e}") raise self.logger.info(f"正在处理 C 文件: {self.c_file_path.name}") start_pos = full_content.find(self.block_start) end_pos = full_content.find(self.block_end) if start_pos == -1: raise ValueError(f"未找到起始锚点: {self.block_start}") if end_pos == -1: raise ValueError(f"未找到结束锚点: {self.block_end}") if end_pos <= start_pos: raise ValueError("结束锚点位于起始锚点之前") inner_start = start_pos + len(self.block_start) block_content = full_content[inner_start:end_pos].strip() all_changes_made = False # === 遍历每一个 rate set 子文件 === for file_path in self.rate_files: try: self.logger.info(f"→ 处理子文件: {file_path.name}") # --- 1. 解析文件名得到 full_key --- try: full_key = self.parse_filename(file_path.name) self.logger.debug(f" ├─ 解析出 key: {full_key}") except ValueError as ve: self.logger.warning(f" └─ 跳过无效文件名: {ve}") continue # --- 2. 查找 rate_set_map 映射 --- target = self.target_map.get(full_key) if not target: self.logger.warning(f" └─ 未在 config.json 中定义映射关系: {full_key},跳过") continue # --- 3. 动态设置当前注入目标 --- self.data_array_name = target["data"] self.index_array_name = target["index"] self.enum_name = target["enum"] self.logger.debug(f" ├─ 绑定目标:") self.logger.debug(f" data: {self.data_array_name}") self.logger.debug(f" index: {self.index_array_name}") self.logger.debug(f" enum: {self.enum_name}") # --- 4. 解析主文件中的当前结构 --- try: parsed = self.parse_all_structures(full_content) except Exception as e: self.logger.error(f" └─ 解析主文件结构失败: {e}") continue # --- 5. 提取该子文件中的 rate sets --- file_content = file_path.read_text(encoding='utf-8') subsets = self.extract_sub_rate_sets(file_content) if not subsets: self.logger.info(f" └─ 无有效子集数据") continue # --- 6. 构建要注入的内容 --- valid_blocks = self.build_injection_with_format( subsets, existing_enum=parsed['existing_enum'] ) if not valid_blocks: self.logger.info(f" └─ 无需更新") continue # --- 7. 写回新内容(精准插入)--- updated_content = self._write_back_in_blocks( full_content, parsed, valid_blocks ) if updated_content != full_content: all_changes_made = True full_content = updated_content # 更新内存内容供后续文件使用 self.logger.info(f"✅ 成功注入 {len(subsets)} 条目到 {self.enum_name}") except Exception as e: self.logger.warning(f"❌ 处理文件失败 [{file_path.name}]: {e}") if self.logger.isEnabledFor(logging.DEBUG): self.logger.debug("详细堆栈:", exc_info=True) continue # 最终写回磁盘 if all_changes_made: try: return self._safe_write_back(self.c_file_path.read_text(encoding='utf-8'), full_content) except Exception as e: self.logger.error(f"写入最终文件失败: {e}") raise else: self.logger.info("没有需要更新的内容") return False你看有问题吗
最新发布
10-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值