Contents
  1. 1. run jar
  2. 2. 更新jar包内class文件
  3. 3. IllegalArgumentException at java.nio.CharBuffer.allocate(CharBuffer.java:334)
  4. 4. 欧元分隔符输出
    1. 4.0.0.0.0.1. Python:以wb模式打开文件
  • 5. 临时代码测试类
  • 6. jshell连接DB
  • run jar

    主类必须是在cp第一个包中,支持*匹配

    更新jar包内class文件

    jar uvf hadoop-common-2.8.3-lg.jar org/apache/hadoop/fs/FileUtil.class

    jar: 包是Java中所特有一种压缩文档
    -u 添加文件到jar包中
    -v 生成详细的报造,并输出至标准设备
    -f 指定jar包的文件名
    [jar文件] jar包的路径
    [欲替换的class(注意,需同样的目录)] class文件目录,必须与jar中目录一样

    IllegalArgumentException at java.nio.CharBuffer.allocate(CharBuffer.java:334)

    原因: 单行数据过大

    问题复现:

    1
    2
    3
    4
    5
    6
    // spark-shell + 本地,触发上述报错,获得文件和行号
    new org.apache.hadoop.io.Text(x)
    // 定位数据
    less +4828553 -N 2021090100_nda_0.txt
    // 过滤数据
    awk '{ if (length($0)<10000) print $0}' 2021090100_nda_0.txt > filter_nda

    欧元分隔符输出

    目标:输出GB2312编码的欧元符€

    方案:需要使用byte方式写出:(不能是char、string)

    1
    2
    3
    4
    5
    6
    7
    8

    FileOutputStream fos = new FileOutputStream(f);
    byte[] bb = new byte[1];
    bb[0] = (byte)0x80; // 即€
    fos.write(bb);
    fos.write("123abc中文".getBytes("gb2312"));
    fos.flush();
    fos.close();

    https://ask.csdn.net/questions/743012

    Python:以wb模式打开文件
    1
    f.write(b'\x80')

    临时代码测试类

    1
    2
    3
    4
    5
    6
    package test;

    javac test/*.java
    java -cp ./ test.T

    java -cp ./*:/data/soft/flink/lib/* rocketMQ.PhotoLiveJob

    jshell连接DB

    还需要加载jar包:

    • jshell –class-path myOwnClassPath
    • /env –class-path /data/soft/zeppelin/local-repo/jdbc/hive-jdbc-uber-2.6.5.0-292.jar
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.DatabaseMetaData;

    public class DBConnectionDemo {
    public static void main(String[] args) {
    // JDBC连接URL
    String url = "jdbc:hive://localhost:3306/mydatabase";
    String u = "root";
    String pw = "password";

    try {
    Class.forName("org.apache.hive.jdbc.HiveDriver");
    // 创建数据库连接
    Connection connection = DriverManager.getConnection(url, u, pw);
    // 在此处执行数据库操作
    DatabaseMetaData meta = connection.getMetaData();
    meta.getDriverName();//zeppelin自动补全功能需要读取到jar包中MANIFEST.MF的Implementation-Title: Hive JDBC字段

    // 关闭连接
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }