⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encoder.java

📁 WAP ide 代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  private String ConvertSpecialChar(String Sequence) {    String value = "";    int pos = ConversionFile.indexOf(Sequence);    pos = ConversionFile.indexOf("=", pos);    if (pos > -1) { // that means the entity was used      pos = pos + 3;      value = ConversionFile.substring(pos, ConversionFile.indexOf(("\n"), pos));    }    else      value = ConversionFile.substring(pos, ConversionFile.indexOf(("\n"), pos));    //now check if there is anything after the ;    String tmp = value.substring(value.indexOf(";") + 1, value.length());    if (tmp.length() > 0)      tmp = tmp.substring(0, 2) + " ";    else      tmp = "";    // now get the value    value = value.substring(0,value.indexOf(";"));    value = Integer.toHexString(Integer.parseInt(value)).toUpperCase();    return tmp + value;  }  /** Helper method concerned with removing extra data, such as tabs, from    the final Hexadecimal stream and setting up the string table that may be    included if there are repetitions among the strings */  private String FinalizeHexStream(String HexOutput, boolean option) {    // Look for tabs in the stream, hex value 9    int TabLocation = 1;    while (TabLocation > -1) {      String temp1 = "";      String temp2 = "";      TabLocation = HexOutput.indexOf(" 9");      if (TabLocation > -1) {        temp1 = HexOutput.substring(0, TabLocation);        temp2 = HexOutput.substring(TabLocation + 2, HexOutput.length());        HexOutput = temp1 + temp2;      }    }    // Look for Hard Returns and soft returns (line feed and enter), A D    int ALocation = 1;    while (ALocation > -1) {      String temp1 = "";      String temp2 = "";      ALocation = HexOutput.indexOf(" A ");      if (ALocation > -1) {        temp1 = HexOutput.substring(0, ALocation);        temp2 = HexOutput.substring(ALocation + 2, HexOutput.length());        HexOutput = temp1 + temp2;      }    }    int DLocation = 1;    while (DLocation > -1) {      String temp1 = "";      String temp2 = "";      DLocation = HexOutput.indexOf(" D ");      if (DLocation > -1) {        temp1 = HexOutput.substring(0, DLocation);        temp2 = HexOutput.substring(DLocation + 2, HexOutput.length());        HexOutput = temp1 + temp2;      }    }    // Get rid of extra tags    int SpaceLocation = 1;    while (SpaceLocation > -1) {      String temp1 = "";      String temp2 = "";      SpaceLocation = HexOutput.indexOf(" 03 00");      if (SpaceLocation > -1) {        temp1 = HexOutput.substring(0, SpaceLocation);        temp2 = HexOutput.substring(SpaceLocation + 6, HexOutput.length());        HexOutput = temp1 + temp2;      }    }    // Seperate the start from the table & the body    String start = HexOutput.substring(0, 8);;    String StringTable = "";    int TableLen = StringTable.length();    if (option == true) {      // Check for repeating strings      String SearchString = "";      String HexValue = "";      int StringFound = -1;      int FilePos = 0;      int StartPos, EndPos;      boolean AddedtoTable = false;      int tmpPos = 0;      int Counter = 0;      int TablePos = 0;      do { // find the string        StartPos = HexOutput.indexOf(" 03", FilePos);        EndPos = HexOutput.indexOf(" 00", StartPos);        FilePos = StartPos + 3;        if (StartPos > -1) { //found a string          SearchString = HexOutput.substring(StartPos, EndPos + 3);          Counter = 0;          tmpPos = 0;          do { // check to see if the string exists more than once            StringFound = HexOutput.indexOf(SearchString, tmpPos);            if (StringFound > -1) {              tmpPos = tmpPos + StringFound + SearchString.length();              Counter++;            }          }          while (StringFound > -1);        }        else          FilePos = -1;        if (Counter > 1) { // Extract the string and put it in the table          StringTable = StringTable + SearchString.substring(3);          TablePos = TablePos + TableLen;          TableLen = StringTable.length() - ((StringTable.length() / 3) * 2);          HexValue = Integer.toHexString(TablePos).toUpperCase();          if (HexValue.length() == 1)            HexValue = "0" + HexValue;          int startPos = 0;          do { // look if there are duplicates & replace them            StringFound = HexOutput.indexOf(SearchString, startPos);            if (StringFound > -1) {              HexOutput = HexOutput.substring(0, StringFound) + " 83 " + HexValue + HexOutput.substring(StringFound + SearchString.length());              startPos = StringFound + SearchString.length();            }          }          while (StringFound >  -1);        }      }      while (FilePos != -1);      do { // find the string        StartPos = HexOutput.indexOf(" 42", FilePos);        EndPos = HexOutput.indexOf(" 00", StartPos);        FilePos = StartPos + 3;        if (StartPos > -1) { //found a string          SearchString = HexOutput.substring(StartPos, EndPos + 3);          Counter = 0;          tmpPos = 0;          do { // check to see if the string exists more than once            StringFound = HexOutput.indexOf(SearchString, tmpPos);            if (StringFound > -1) {              tmpPos = tmpPos + StringFound + SearchString.length();              Counter++;            }          }          while (StringFound > -1);        }        else          FilePos = -1;        if (Counter > 1) { // Extract the string and put it in the table          StringTable = StringTable + SearchString.substring(3);          TablePos = TablePos + TableLen;          TableLen = StringTable.length() - ((StringTable.length() / 3) * 2);          HexValue = Integer.toHexString(TablePos).toUpperCase();          if (HexValue.length() == 1)            HexValue = "0" + HexValue;          int startPos = 0;          do { // look if there are duplicates & replace them            StringFound = HexOutput.indexOf(SearchString, startPos);            if (StringFound > -1) {              HexOutput = HexOutput.substring(0, StringFound) + " 82 " + HexValue + HexOutput.substring(StringFound + SearchString.length());              startPos = StringFound + SearchString.length();            }          }          while (StringFound >  -1);        }      }      while (FilePos != -1);    }    // If at the end of the file there are no strings that repeat    // then the string table stays empty    if (TableLen == 0)      StringTable = " 00";    else {      String len = Integer.toHexString(TableLen).toUpperCase();      if (len.length() == 1)        len = "0" + len;      StringTable = " " + len + StringTable;    }    // Add the string table    HexOutput = start + StringTable + HexOutput.substring(8, HexOutput.length());    return HexOutput;  }  /** Reads a file and then returns the text of the file.   * @param String filename - the file to read.   * @return String text - the file text.   */  private String ReadFile(String fileName) {    FileInputStream fis = null;    String str = null;    try {      fis = new FileInputStream (fileName);      int size = fis.available ();      byte[] bytes = new byte [size];      fis.read (bytes);      str = new String (bytes);    }    catch (IOException e) {      ErrorMessage = ErrorMessage + e.getMessage() + "\n";    }    try {      fis.close ();    }    catch (IOException e) {      ErrorMessage = ErrorMessage + e.getMessage() + "\n";    }    return str;  }  /**   * Writes the new xbxml file.   * @param String fileName - name of file to write.   * @param String fileData - the data to write.   */  private void WriteFile(String fileName, String fileData) {    FileOutputStream fos = null;    String str = fileData;    int filePos = -1;    int value = 0;    int counter = 0;    try {      File f = new File(fileName);      boolean fexists = f.createNewFile();      if (!fexists) {        // need to display some type of dialog        int selOption = JOptionPane.showConfirmDialog(null, "File Exists, do you wish to overwrite the file", "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);        switch (selOption) {          case JOptionPane.YES_OPTION:            FileOutputStream DataOut = new FileOutputStream(fileName);            do { // Extract the hex numbers              filePos++;              value = HextoInt(str.substring(filePos, filePos + 2));              counter++;              filePos = str.indexOf(" ", filePos);              DataOut.write(value); // and write them as integers, one by one            }            while (filePos > -1);            DataOut.close();            break;          case JOptionPane.NO_OPTION:            // display a file rename dialog box            String[] filters = {"wmlc", "wmlsc", "sic", "slc"};            Designer.Filter filter = new Designer.Filter(filters, "WAP Files");            JFileChooser fc = new JFileChooser();            fc.addChoosableFileFilter(filter);            fc.setCurrentDirectory(new File(fileName));            fc.setSelectedFile(new File(fileName));            fc.setDialogTitle("Rename File As");            fc.setApproveButtonText("Rename");            fc.setApproveButtonToolTipText("Rename the file");            int retVal = fc.showDialog(null, "Rename");            if (retVal == fc.APPROVE_OPTION) {              // Get the path & the file name              String path = fc.getSelectedFile().getParent() + File.separator;              String fname = fc.getSelectedFile().getPath().substring(path.length());              FileName = path + fname;              WriteFile(FileName, str);            }            break;        }      }      else {        FileOutputStream DataOut = new FileOutputStream(fileName);        do { // Extract the hex numbers          filePos++;          value = HextoInt(str.substring(filePos, filePos + 2));          counter++;          filePos = str.indexOf(" ", filePos);          DataOut.write(value); // and write them as integers, one by one        }        while (filePos > -1);        DataOut.close();      }    }    catch (IOException e) {      ErrorMessage = ErrorMessage + e.getMessage() + "\n";    }  }  /** Converts a string, 2 characters, into a hex value */  private String StringtoHex(String theChar) { // The 1st 3 lines of this    // algorith where taken    // from Sun Microsystems    char c = theChar.charAt(0);    byte hi = (byte) (c >>> 8);    byte lo = (byte) (c & 0xff);    String Converted = Byte.toString(hi) + Byte.toString(lo);    int dec = Integer.parseInt(Converted);    return Integer.toHexString(dec).toUpperCase();  }    /*8 Used to get the decimal equivelant of the hex string so    that it can be stored as hex data in the output file */  private int HextoInt(String hexValue) {    String hexDigit = "0123456789ABCDEF";    int HextoIntValue = (hexDigit.indexOf(hexValue.substring(0,1)) * 16) + hexDigit.indexOf(hexValue.substring(1,2));    return HextoIntValue;  }  /**   * Use this method to retrieve any error messages generated.   * It was put into this class to be used in the IDE.   */  public String ReturnErrors() {    return ErrorMessage;  }  /**   * The main method, used when encoder runs as a stand-alone program.   */  public static void main(String args[]){    Encoder WapEncoder = new Encoder(args[0]);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -