コード例 #1
0
 public void convert(String desFld) throws FileNotFoundException {
   desFld = getFolderString(desFld);
   File idxFile = new File(desFld + CSINDEXFILE);
   _ZipFile zFile = null;
   OutputStream osIdx = null;
   try {
     zFile = new _ZipFile(desFld + CSDATAFILE, "w");
     osIdx = new BufferedOutputStream(new FileOutputStream(idxFile));
     int size = index2.getSize();
     String word, id;
     int offset;
     byte[] data;
     VoiceIndex2Item item2;
     osIdx.write(0xff);
     osIdx.write(0xfe);
     for (int i = 0; i < size; i++) {
       item2 = (VoiceIndex2Item) index2.getItem(i);
       word = new String(item2.getData());
       id = String.valueOf(i);
       offset = item2.getDataIndex();
       data = getVoiceData(offset);
       osIdx.write(getBytesNoBom(word));
       osIdx.write(getBytesNoBom("\t"));
       osIdx.write(getBytesNoBom(id));
       osIdx.write(LSBYTES);
       zFile.write(id, data);
     }
   } catch (FileNotFoundException e) {
     Logger.err(e);
   } catch (IOException e) {
     Logger.err(e);
   } finally {
     try {
       if (zFile != null) zFile.close();
       if (osIdx != null) osIdx.close();
     } catch (IOException e) {
       Logger.err(e);
     }
   }
 }
コード例 #2
0
ファイル: Pack.java プロジェクト: yindian/dicparser
  /**
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    getMap(args[0]);
    String srcFld = args[1];
    File idxFile = new File(args[2]);
    _ZipFile zFile = new _ZipFile(args[3], "w");
    OutputStream osIdx = null;
    osIdx = new BufferedOutputStream(new FileOutputStream(idxFile));

    String word;
    String name;
    String[] names;
    Iterator it = fileNameMap.entrySet().iterator();
    int count = 0;
    osIdx.write(0xff);
    osIdx.write(0xfe);
    while (it.hasNext()) {
      Entry entry = (Entry) it.next();
      word = (String) entry.getKey();
      name = (String) entry.getValue();
      names = name.split(",");
      osIdx.write(StringUtil.getBytesNoBom(word, CommonConstants.ENCODING));
      osIdx.write(CommonConstants.SEPARATORBYTES);
      osIdx.write(StringUtil.getBytesNoBom(name, CommonConstants.ENCODING));
      osIdx.write(CommonConstants.LSBYTES);
      if (!nameMap.contains(name)) {
        nameMap.add(name);
        zFile.write(name, 0xff);
        zFile.write(0xfe);
        zFile.write(StringUtil.getBytesNoBom("<CK>", CommonConstants.ENCODING));
        zFile.write(StringUtil.getBytesNoBom("<XX></XX>", CommonConstants.ENCODING));
        zFile.write(StringUtil.getBytesNoBom("<JX><![CDATA[", CommonConstants.ENCODING));
        for (int i = 0; i < names.length; i++) {
          if (i != 0) zFile.write(CommonConstants.HBARBYTES);
          zFile.write(
              FileUtil.getBytesFromFile(
                  Common.getFile(srcFld, Integer.valueOf(names[i]).intValue())));
        }
        zFile.write(CommonConstants.KSDICEBYTES);
        zFile.write(0);
        zFile.write(0);
      }
      if (count % 100 == 0) {
        Logger.info(count);
      }
      count++;
    }

    zFile.close();
    osIdx.close();
  }