public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();

    // write header
    buffer = header.write(buffer, c, true);

    // write fields
    for (FieldPacket field : fields) {
      buffer = field.write(buffer, c, true);
    }

    // write eof
    buffer = eof.write(buffer, c, true);

    // write rows
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(VERSION_COMMENT);
    row.packetId = ++packetId;
    buffer = row.write(buffer, c, true);

    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);

    // post write
    c.write(buffer);
  }
Esempio n. 2
0
 private static PackageBufINf showInfo(
     ManagerConnection c, ByteBuffer buffer, byte packetId, String string) {
   PackageBufINf bufINf = new PackageBufINf();
   RowDataPacket row = new RowDataPacket(FIELD_COUNT);
   row.add(StringUtil.encode(string, c.getCharset()));
   row.packetId = ++packetId;
   buffer = row.write(buffer, c, true);
   bufINf.packetId = packetId;
   bufINf.buffer = buffer;
   return bufINf;
 }
Esempio n. 3
0
  private static PackageBufINf listConfigFiles(
      ManagerConnection c, ByteBuffer buffer, byte packetId) {
    PackageBufINf bufINf = new PackageBufINf();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    try {
      int i = 1;
      File[] file = new File(SystemConfig.getHomePath(), "conf").listFiles();
      for (File f : file) {
        if (f.isFile()) {
          RowDataPacket row = new RowDataPacket(FIELD_COUNT);
          row.add(
              StringUtil.encode(
                  (i++) + " : " + f.getName() + "  time:" + df.format(new Date(f.lastModified())),
                  c.getCharset()));
          row.packetId = ++packetId;
          buffer = row.write(buffer, c, true);
        }
      }

      bufINf.buffer = buffer;
      bufINf.packetId = packetId;
      return bufINf;

    } catch (Exception e) {
      e.printStackTrace();
      RowDataPacket row = new RowDataPacket(FIELD_COUNT);
      row.add(StringUtil.encode(e.toString(), c.getCharset()));
      row.packetId = ++packetId;
      buffer = row.write(buffer, c, true);
      bufINf.buffer = buffer;
    }
    bufINf.packetId = packetId;
    return bufINf;
  }
Esempio n. 4
0
  private static PackageBufINf showConfigFile(
      ManagerConnection c, ByteBuffer buffer, byte packetId, String fileName) {
    File file = new File(SystemConfig.getHomePath(), "conf" + File.separator + fileName);
    BufferedReader br = null;
    PackageBufINf bufINf = new PackageBufINf();
    try {
      br = new BufferedReader(new FileReader(file));
      String line = null;
      while ((line = br.readLine()) != null) {
        if (line.isEmpty()) {
          continue;
        }
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(line, c.getCharset()));
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
      }
      bufINf.buffer = buffer;
      bufINf.packetId = packetId;
      return bufINf;

    } catch (Exception e) {
      e.printStackTrace();
      RowDataPacket row = new RowDataPacket(FIELD_COUNT);
      row.add(StringUtil.encode(e.toString(), c.getCharset()));
      row.packetId = ++packetId;
      buffer = row.write(buffer, c, true);
      bufINf.buffer = buffer;
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    bufINf.packetId = packetId;
    return bufINf;
  }