Example #1
0
  private void writeLogEntry(PrintWriter out, LogEntry logEntry) {
    if (logEntry.getEntriesCount() == 0) {
      return;
    }

    String message = logEntry.getMessage().replace(QUOTE_CHARACTER, QUOTE_SPECIAL_CHARACTER);
    message =
        message.replace(ANGLE_OPENING_BRACKET_CHARACTER, ANGLE_OPENING_BRACKET_SPECIAL_CHARACTER);
    message =
        message.replace(ANGLE_CLOSING_BRACKET_CHARACTER, ANGLE_CLOSING_BRACKET_SPECIAL_CHARACTER);

    out.println(
        MessageFormat.format(
            LOGENTRY_START_NODE,
            new String[] {message, Integer.toString(logEntry.getRevision()), logEntry.getDate()}));

    List<PathEntry> pathEntries = logEntry.getPathEntries();
    for (PathEntry pathEntry : pathEntries) {
      out.println(
          MessageFormat.format(
              PATH_NODE, new String[] {pathEntry.getAction(), pathEntry.getPath()}));
    }

    out.println(LOGENTRY_END_NODE);
  }
Example #2
0
 /**
  * ** Gets the Localized value for the specified key. The default String text is return if ** the
  * specified key does not exist ** @param key The LocalStrings key ** @param dft The default
  * String text to return if the LocalStrings key does not exist ** @param args An array of
  * replacement fields ** @return The Localized String text
  */
 public String getString(String key, String dft, Object args[]) {
   String val = this.getString(key, dft);
   if ((args != null) && (args.length > 0) && (val != null)) {
     try {
       MessageFormat mf = new MessageFormat(val);
       mf.setLocale(this.locale);
       StringBuffer sb = mf.format(args, new StringBuffer(), null);
       return I18N.decodeNewLine(sb).toString();
     } catch (Throwable th) {
       Print.logInfo("Exception: " + key + " ==> " + val);
     }
   }
   return I18N.decodeNewLine(val);
 }
Example #3
0
 void open(java.lang.String name) {
   final java.lang.String textString;
   if (name == null || name.length() == 0) {
     return;
   }
   java.io.File file = new java.io.File(name);
   if (!file.exists()) {
     java.lang.String message =
         MessageFormat.format(
             resources.getString("Err_file_no_exist"), new java.lang.String[] {file.getName()});
     displayError(message);
     return;
   }
   try {
     java.io.FileInputStream stream = new java.io.FileInputStream(file.getPath());
     try {
       java.io.Reader in = new java.io.BufferedReader(new java.io.InputStreamReader(stream));
       char[] readBuffer = new char[2048];
       java.lang.StringBuffer buffer = new java.lang.StringBuffer((int) file.length());
       int n;
       while ((n = in.read(readBuffer)) > 0) {
         buffer.append(readBuffer, 0, (-n));
       }
       textString = buffer.toString();
       stream.close();
     } catch (java.io.IOException e) {
       java.lang.String message =
           MessageFormat.format(
               resources.getString("Err_file_io"), new java.lang.String[] {file.getName()});
       displayError(message);
       return;
     }
   } catch (java.io.FileNotFoundException e) {
     java.lang.String message =
         MessageFormat.format(
             resources.getString("Err_not_found"), new java.lang.String[] {file.getName()});
     displayError(message);
     return;
   }
   org.eclipse.swt.widgets.Display display = text.getDisplay();
   display.asyncExec(
       new java.lang.Runnable() {
         public void run() {
           text.setText(textString);
         }
       });
   lineStyler.parseBlockComments(textString);
 }
    private String formatString(
        MLevel l, String srcClass, String srcMeth, String msg, Object[] params, Throwable t) {
      boolean add_parens = (srcMeth != null && !srcMeth.endsWith(")"));

      StringBuffer sb = new StringBuffer(256);
      sb.append(l.getLineHeader());
      sb.append(' ');
      if (srcClass != null && srcMeth != null) {
        sb.append('[');
        sb.append(srcClass);
        sb.append('.');
        sb.append(srcMeth);
        if (add_parens) sb.append("()");
        sb.append(']');
      } else if (srcClass != null) {
        sb.append('[');
        sb.append(srcClass);
        sb.append(']');
      } else if (srcMeth != null) {
        sb.append('[');
        sb.append(srcMeth);
        if (add_parens) sb.append("()");
        sb.append(']');
      }
      if (msg == null) {
        if (params != null) {
          sb.append("params: ");
          for (int i = 0, len = params.length; i < len; ++i) {
            if (i != 0) sb.append(", ");
            sb.append(params[i]);
          }
        }
      } else {
        if (params == null) sb.append(msg);
        else {
          MessageFormat mfmt = new MessageFormat(msg);
          sb.append(mfmt.format(params));
        }
      }

      if (t != null) {
        sb.append(SEP);
        sb.append(ThrowableUtils.extractStackTrace(t));
      }

      return sb.toString();
    }
Example #5
0
 public java.lang.String getResourceString(java.lang.String key, java.lang.Object[] args) {
   try {
     return MessageFormat.format(getResourceString(key), args);
   } catch (java.util.MissingResourceException e) {
     return key;
   } catch (java.lang.NullPointerException e) {
     return "!" + key + "!";
   }
 }
Example #6
0
  /**
   * Return the specified localized text for a given locale and replace the parameters with an array
   * of arguments.
   *
   * @since 0.2
   * @param key the text key in the resource bundle
   * @param locale the locale of the message
   * @param arguments the array of arguments
   */
  public static String getText(String key, Locale locale, Object... arguments) {
    // localize the arguments
    Object[] arguments2 = new Object[arguments.length];
    for (int i = 0; i < arguments.length; i++) {
      arguments2[i] = getLocalizedArgument(locale, arguments[i]);
    }

    return MessageFormat.format(getText(key, locale), arguments2);
  }
 /**
  * Gets a string from the resource bundle and binds it with the given arguments. If the key is not
  * found, return the key.
  */
 static String getResourceString(String key, Object[] args) {
   try {
     return MessageFormat.format(getResourceString(key), args);
   } catch (MissingResourceException e) {
     return key;
   } catch (NullPointerException e) {
     return "!" + key + "!"; // $NON-NLS-1$ //$NON-NLS-2$
   }
 }
Example #8
0
 /**
  * getLocalizedMessage is used to localize the messages being used in exceptions with arguments
  * inserted appropriately.
  */
 public static String getLocalizedMessage(Logger logger, String key, Object[] args) {
   try {
     ResourceBundle rb = logger.getResourceBundle();
     String message = rb.getString(key);
     return MessageFormat.format(message, args);
   } catch (Exception ex) {
     logger.log(Level.FINE, "JTS:Error while localizing the log message");
     return key;
   }
 }
Example #9
0
  public static String format(String message, Object[] args) {
    MessageFormat mf;
    String msg;

    try {
      mf = (MessageFormat) _formats.get(message);
      if (mf == null) {
        try {
          msg = _messages.getString(message);
        } catch (MissingResourceException except) {
          return message;
        }
        mf = new MessageFormat(msg);
        _formats.put(message, mf);
      }
      return mf.format(args);
    } catch (Exception except) {
      return "An internal error occured while processing message " + message;
    }
  }
    @Override
    public void actionPerformed(ActionEvent e) {
      if (fc == null) {
        fc = new IDEFileChooser();
        fc.setFileView(new IDEFileView());
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
        fc.setDialogTitle(
            messagesBundle.getString("ImageViewerPanelSaveAction.Choose_filename_to_save_4"));

        //$NON-NLS-1$

        // prepare file filters
        IIORegistry theRegistry = IIORegistry.getDefaultInstance();
        Iterator it = theRegistry.getServiceProviders(ImageWriterSpi.class, false);
        while (it.hasNext()) {
          ImageWriterSpi writer = (ImageWriterSpi) it.next();
          if ((imageType == BufferedImage.TYPE_INT_ARGB
                  || imageType == BufferedImage.TYPE_INT_ARGB_PRE)
              && "JPEG".equals(writer.getFormatNames()[0].toUpperCase())) continue;
          ImageWriterSpiFileFilter ff = new ImageWriterSpiFileFilter(writer);
          fc.addChoosableFileFilter(ff);
        }
      }

      if (fc.showSaveDialog(viewerPanel) == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fc.getSelectedFile();

        if (selectedFile != null) {
          String fileName = selectedFile.getAbsolutePath();
          ImageWriterSpiFileFilter ff = (ImageWriterSpiFileFilter) fc.getFileFilter();
          if (!ff.hasCorrectSuffix(fileName)) fileName = ff.addSuffix(fileName);
          selectedFile = new File(fileName);
          if (selectedFile.exists()) {
            String message =
                MessageFormat.format(
                    messagesBundle.getString("ImageViewerPanelSaveAction.Overwrite_question_5"),
                    //$NON-NLS-1$
                    fileName);
            if (JOptionPane.NO_OPTION
                == JOptionPane.showConfirmDialog(
                    viewerPanel,
                    message,
                    messagesBundle.getString("ImageViewerPanelSaveAction.Warning_6"),
                    //$NON-NLS-1$
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE)) return;
          }
          writeToFile(selectedFile, ff);
        }
      }
    }
Example #11
0
  private void writeSummary(PrintWriter out) {
    out.println(SUMMARY_START_NODE);
    out.println(
        MessageFormat.format(
            CHANGES_START_NODE, new String[] {Integer.toString(getLogEntriesCount())}));

    List<String> authors = getAuthors();
    for (String author : authors) {
      out.println(
          MessageFormat.format(
              AUTHOR_SUMMARY_NODE,
              new String[] {
                author,
                Integer.toString(getAuthorLogEntriesCount(author)),
                Integer.toString(getAuthorLogEntriesPercent(author))
              }));
    }

    out.println(CHANGES_END_NODE);
    out.println(SUMMARY_END_NODE);
  }
Example #12
0
 @Override
 public synchronized String toString() {
   return STAND_ALONE_ENTRY_FORMAT.format(
       new Object[] {
         query == null ? "TOTALS" : query,
         numQueries,
         (queriesPrepared - queriesCompiled) / (double) queriesPrepared,
         queryTime,
         queryCompilationTime,
         queryPreparationTime,
         queryRunTime,
         queryTime * 1000 / numQueries,
         queriesCompiled == 0 ? 0 : queryCompilationTime * 1000 / queriesCompiled,
         queriesPrepared == 0 ? 0 : queryPreparationTime * 1000 / queriesPrepared,
         queriesRun == 0 ? 0 : queryRunTime * 1000 / queriesRun
       });
 }
Example #13
0
 public synchronized String toString(int maxCountLength, double totalDuration) {
   String formattedCount =
       String.format("%" + maxCountLength + "s", COUNT_FORMAT.format(numQueries));
   return FULL_ENTRY_FORMAT.format(
       new Object[] {
         query == null ? "TOTALS" : query,
         formattedCount,
         (queriesPrepared - queriesCompiled) / (double) queriesPrepared,
         queryTime,
         queryCompilationTime,
         queryPreparationTime,
         queryRunTime,
         queryTime * 1000 / numQueries,
         queriesCompiled == 0 ? 0 : queryCompilationTime * 1000 / queriesCompiled,
         queriesPrepared == 0 ? 0 : queryPreparationTime * 1000 / queriesPrepared,
         queriesRun == 0 ? 0 : queryRunTime * 1000 / queriesRun,
         queryTime / totalDuration
       });
 }
Example #14
0
 public String getDayUrl(int dayOfWeek) {
   String part = "";
   switch (dayOfWeek) {
     case Calendar.MONDAY:
       part = "pondeli";
       break;
     case Calendar.TUESDAY:
       part = "utery";
       break;
     case Calendar.WEDNESDAY:
       part = "streda";
       break;
     case Calendar.THURSDAY:
       part = "ctvrtek";
       break;
     case Calendar.FRIDAY:
       part = "patek";
       break;
   }
   return MessageFormat.format("{0}/{1}", urlPrefix, part);
 }
Example #15
0
    private String stats() {

      String minString, averageString, maxString, totalString, deviationString;

      // compute string representing stats values
      if (valueCount == 0) {
        minString = "0";
        averageString = "0";
        maxString = "0";
        totalString = "0";
        deviationString = "0";
      } else {
        minString = ((long) (minValue / outputFactor)) + "";
        maxString = ((long) (maxValue / outputFactor)) + "";
        totalString = ((long) (totalCount / outputFactor)) + "";
        if (minValue == maxValue) {
          averageString = minString;
          deviationString = "0";
        } else {
          double average = totalCount / valueCount / outputFactor;
          double deviation = sqrt((totalCount2 / valueCount) - average * average);
          averageString = Double.toString(average);
          deviationString = Double.toString(deviation);
        }
      }

      // return stats values according to format
      String[] args =
          new String[] {
            averageString,
            valueCount + "",
            deviationString,
            minString,
            maxString,
            nullCount + "",
            totalString
          };
      return outputFormat.format(args);
    }
Example #16
0
  private void writeChanges(PrintWriter out) {
    List<String> authors = getAuthors();
    for (String author : authors) {
      List<LogEntry> logEntries = getOrderedAuthorLogEntries(author);
      if (logEntries == null || logEntries.isEmpty()) {
        continue;
      }

      out.println(
          MessageFormat.format(
              AUTHOR_START_NODE,
              new String[] {
                author,
                Integer.toString(getAuthorLogEntriesCount(author)),
                Integer.toString(logEntries.size())
              }));

      for (LogEntry logEntry : logEntries) {
        writeLogEntry(out, logEntry);
      }

      out.println(AUTHOR_END_NODE);
    }
  }
Example #17
0
  public static String getTimeShow(String dateString) {
    Date thenDate = stringToDate(dateString);
    Calendar then = Calendar.getInstance();
    then.setTime(thenDate);
    Calendar current = Calendar.getInstance();

    long differ = current.getTimeInMillis() - then.getTimeInMillis();

    if (differ < 0) {
      return "Milai";
    } else {
      if (differ >= 0L && differ < 300000L) {
        return "Just now";
      }

      if (differ >= 300000L && differ < 10800000L) {
        return MessageFormat.format("{0}:{1}", then.get(Calendar.HOUR), then.get(Calendar.MINUTE));
      }

      if (then.get(Calendar.YEAR) != current.get(Calendar.YEAR)) {
        return MessageFormat.format(
            "{0}/{1}/{2}",
            then.get(Calendar.YEAR) - 2000, then.get(Calendar.MONTH), then.get(Calendar.DATE));
      }

      if (current.get(Calendar.DAY_OF_YEAR) - then.get(Calendar.DAY_OF_YEAR) == 1) {
        return "Yesterday";
      }

      if (then.get(Calendar.MONTH) != current.get(Calendar.MONTH)) {
        MDebug.log("[DATE]" + then.get(Calendar.DATE));
        return MessageFormat.format(
            "{0}/{1}/{2}",
            then.get(Calendar.YEAR) - 2000,
            then.get(Calendar.MONTH),
            then.get(Calendar.DAY_OF_MONTH));
      }

      int dayDiff = current.get(Calendar.DAY_OF_MONTH) - then.get(Calendar.DAY_OF_MONTH);
      if (dayDiff > 7) {
        return MessageFormat.format(
            "{0}/{1}/{2}",
            then.get(Calendar.YEAR) - 2000, then.get(Calendar.MONTH), then.get(Calendar.DATE));
      } else {
        if (dayDiff == 0) {
          int hour = then.get(Calendar.HOUR);
          if (0 <= hour && hour < 5) {
            return "MidNight";
          } else if (5 <= hour && hour < 12) {
            return "BeforeNoon";
          } else if (12 <= hour && hour < 19) {
            return "AfterNoon";
          } else if (19 <= hour && hour != 0) {
            return "Night";
          }
        }

        if (current.get(Calendar.WEEK_OF_MONTH) == then.get(Calendar.WEEK_OF_MONTH)) {
          return getDayString(then.get(Calendar.DAY_OF_WEEK));
        } else {
          return MessageFormat.format(
              "{0}/{1}/{2}",
              then.get(Calendar.YEAR) - 2000, then.get(Calendar.MONTH), then.get(Calendar.DATE));
        }
      }
    }
  }
Example #18
0
 private void throwException(String operation, DataElement element) {
   throw new IllegalArgumentException(
       MessageFormat.format(
           TEMPLATE, new Object[] {operation, element, this.getClass().getName()}));
 }
Example #19
0
  public int doEndTag() throws JspException {
    String pattern = this.pattern;
    ResourceBundle bundle = null;

    // get pattern from bundle
    if (pattern == null) {
      String prefix = null;

      bundle = this.bundle;
      if (bundle == null) {
        BundleTag bundleTag = (BundleTag) findAncestorWithClass(this, BundleTag.class);
        if (bundleTag != null) {
          bundle = bundleTag.getBundle();
          prefix = bundleTag.getPrefix();
        }
      }
      if (bundle == null) {
        bundle = I18nUtil.findBundle(pageContext);
      }

      // get message
      try {
        pattern = bundle.getString(prefix != null ? prefix + this.key : this.key);
      } catch (Exception e) {
        pattern = "???" + this.key + "???";
      }
    }

    // format message
    String message = pattern;
    if ((this.pattern != null || bundle != null) && this.params.size() != 0) {
      // set timezone on formatters
      TimeZone timeZone = null;
      TimeZoneTag timeZoneTag = (TimeZoneTag) findAncestorWithClass(this, TimeZoneTag.class);
      if (timeZoneTag != null) timeZone = timeZoneTag.getTimeZone();
      if (timeZone == null) timeZone = I18nUtil.findTimeZone(pageContext);

      MessageFormat formatter = new MessageFormat(pattern, I18nUtil.findLocale(pageContext));
      for (Format format : formatter.getFormatsByArgumentIndex()) {
        if (format != null && format instanceof DateFormat) {
          ((DateFormat) format).setTimeZone(timeZone);
        }
      }

      // now format!
      message = formatter.format(getParams());
    }

    // output text
    if (this.var == null) {
      try {
        pageContext.getOut().print(message);
      } catch (IOException e) {
        throw new JspException(e);
      }
    }

    // store result
    else {
      pageContext.setAttribute(this.var, message, this.scope);
    }

    // clear old state
    this.pattern = null;
    this.bundle = null;
    this.key = null;
    this.var = null;
    this.scope = PageContext.PAGE_SCOPE;

    // continue with page
    return EVAL_PAGE;
  }
Example #20
0
  private void _displayImgInFrame() {

    final JFrame frame = new JFrame("Google Static Map");
    GUIUtils.setAppIcon(frame, "71.png");
    // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JLabel imgLbl = new JLabel(new ImageIcon(_img));
    imgLbl.setToolTipText(
        MessageFormat.format(
            "<html>Image downloaded from URI<br>size: w={0}, h={1}</html>",
            _img.getWidth(), _img.getHeight()));

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
    frame.setContentPane(imgLbl);
    frame.pack();
    frame.setResizable(false);

    imgLbl.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {

            System.out.println("Mouse Listener:  Mouse Clicked!");
            mapIsUp = 1;
            sentX = 0.00;
            clickX = e.getX(); // Latitude
            clickY = e.getY(); // Longitude
            if ((clickX < (_img.getWidth() / 2))
                && (clickY < (_img.getHeight() / 2))) { // 1st quadrant positive values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX); // Add to latitude
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY); // Add to Longitude
              System.out.println("Top left");
            } else if ((clickX > (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 2nd quadrant negative values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Right");
            } else if ((clickX < (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Left");
            } else { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Top Right");
            }

            BigDecimal toCoordsX = new BigDecimal(sentX);
            BigDecimal toCoordsY = new BigDecimal(sentY);

            sentX =
                (toCoordsX.setScale(6, BigDecimal.ROUND_HALF_UP))
                    .doubleValue(); // allows values of up to 6 decimal places
            sentY = (toCoordsY.setScale(6, BigDecimal.ROUND_HALF_UP)).doubleValue();
            getCoords = sentX + " " + sentY;
            ttfLati.setText(Double.toString(sentX));
            ttfLongi.setText(Double.toString(sentY));

            System.out.println("... saving Coordinates");
            saveLocation(
                getCoords); // pass getCoords through saveLocation. this string is appended to the
                            // savedLocations file.
            System.out.println("... savedCoordinates");

            // Update the Locations ComboBox with new additions
            ttfSave.removeAllItems(); // re-populate the ComboBox
            System.out.println("removed items");

            getSavedLocations(); // run through file to get all locations
            for (int i = 0; i < loc.size(); i++) ttfSave.addItem(loc.get(i));
            System.out.println("update combobox");
            mapIsUp = 0;
            frame.dispose(); // closes window
            startTaskAction(); // pops up a new window
          }

          public void saveLocation(String xy) {
            BufferedWriter f = null; // created a bufferedWriter object

            try {
              f =
                  new BufferedWriter(
                      new FileWriter(
                          "savedLocations.txt",
                          true)); // evaluated true if file has not been created yet
              f.write(xy); // append passed coordinates and append to file if exists
              f.newLine();
              f.flush();
            } catch (IOException ioe) {
              ioe.printStackTrace();
            } finally { // close the file
              if (f != null) {

                try {
                  f.close();
                } catch (IOException e) { // any error, catch exception
                  System.err.println("Error: " + e.getMessage());
                }
              }
            }
          }

          public void mouseReleased(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}
        });
  }
Example #21
0
  /**
   * Parse the section file and fill in the Dbase.
   *
   * @return Success code
   */
  public void parse() throws Exception {
    JOAParameter tempProperties[] = new JOAParameter[100];
    FileInputStream in = null;
    DataInputStream inData = null;
    short inShort = 0;
    long bytesRead = 0;
    long bytesInFile = mFile.length();
    short[] sarray = new short[1];
    int mTotalStns = 0;

    EPSProgressDialog mProgress = new EPSProgressDialog(new Frame(), mProgressStr, Color.blue);
    mProgress.setVisible(true);

    // Get an epic key database specific to JOA
    EPIC_Key_DB mEpicKeyDB = new EPIC_Key_DB("joa_epic.key");

    // Get an epic key database specific to JOA
    EPIC_Key_DB mOrigEpicKeyDB = new EPIC_Key_DB("epic.key");

    // create a vector for temporary storage of the dbases
    Vector dBases = new Vector(100);

    try {
      in = new FileInputStream(mFile);
      BufferedInputStream bis = new BufferedInputStream(in, 1000000);
      inData = new DataInputStream(bis);

      // read version
      short vers = inData.readShort();
      bytesRead += 2;

      if (vers < 2) {
        FileImportException fiex = new FileImportException();
        String errStr = "Invalid version for a JOA binary file";
        fiex.setErrorType(errStr);
        throw fiex;
      }

      // read number of bytes in file description string
      inShort = inData.readShort();
      bytesRead += 2;

      // read the file description String
      byte buf[] = new byte[inShort];
      inData.read(buf, 0, inShort);
      String fileDescrip = new String(buf);
      bytesRead += inShort;

      // create a new open file object
      JOADataFile of = new JOADataFile(fileDescrip);

      // read the number of sections
      int numSections = inData.readShort();
      bytesRead += 2;

      // read each section
      JOASection sech;
      int ord = 0;
      for (int s = 0; s < numSections; s++) {
        mProgress.setPercentComplete(100.0 * ((double) bytesRead / (double) bytesInFile));

        // read the section header
        inShort = inData.readShort();
        bytesRead += 2;
        byte buf1[] = new byte[inShort];
        inData.read(buf1, 0, inShort);
        String sectionDescrip = new String(buf1);
        bytesRead += inShort;

        // read the ship code
        byte bufsc[] = new byte[2];
        bufsc[0] = inData.readByte();
        bufsc[1] = inData.readByte();
        String shipCode = new String(bufsc);
        bytesRead += 2;

        // read num casts
        int numCasts = inData.readShort();
        bytesRead += 2;

        // read num parameters
        int numVars = inData.readShort();
        bytesRead += 2;

        // quality code
        int qcStd = 1;
        if (vers == 4) {
          qcStd = inData.readShort();
          bytesRead += 2;
        }

        // create a new section
        of.mNumSections++;
        sech = new JOASection(of.mNumSections, sectionDescrip, shipCode, numCasts, numVars);

        if (vers == 2) {
          // read the properties
          byte bufv[] = new byte[4];
          for (int p = 0; p < numVars; p++) {
            // parameter name
            inData.read(bufv, 0, 4);
            String tempVar = new String(bufv);
            bytesRead += 4;

            // units
            inShort = inData.readShort();
            bytesRead += 2;

            String units = null;
            if (inShort > 0) {
              byte buf11[] = new byte[inShort];
              inData.read(buf11, 0, inShort);
              units = new String(buf11);
              bytesRead += inShort;
            }

            // convert varnames to UC
            tempVar.toUpperCase();

            // create new property
            tempProperties[p] = new JOAParameter(tempVar, units);

            // add this property to the section property list
            if (tempProperties[p].mUnits == null) {
              tempProperties[p].mUnits =
                  EPS_Util.paramNameToJOAUnits(false, tempProperties[0].mVarLabel);
            }

            if (tempProperties[p].mUnits == null) {
              tempProperties[p].mUnits = new String("na");
            }
            tempProperties[p].mCastOrObs = EPSConstants.ALL_OBS;

            // read the actual scale
            int actScale = inData.readShort();
            bytesRead += 2;

            if (actScale != 0) tempProperties[p].mActScale = 1.0 / (double) actScale;
            else tempProperties[p].mActScale = 1.0;

            // read the actual origin
            int actOrigin = inData.readShort();
            tempProperties[p].mActOrigin = (double) actOrigin * tempProperties[p].mActScale;

            // read reverse y
            int reverseY = inData.readShort();
            bytesRead += 2;

            if (reverseY == 0) tempProperties[p].mReverseY = false;
            else tempProperties[p].mReverseY = true;

            tempProperties[p].mWasCalculated = false;
          }
        } else {
          // read the properties
          String tempVar = null;
          for (int p = 0; p < numVars; p++) {
            // length of parameter name
            inShort = inData.readShort();
            bytesRead += 2;

            // parameter name
            if (inShort > 0) {
              byte buf13[] = new byte[inShort];
              inData.read(buf13, 0, inShort);
              tempVar = new String(buf13);
              bytesRead += inShort;
            }

            // units
            inShort = inData.readShort();
            bytesRead += 2;

            String units = null;
            if (inShort > 0) {
              byte buf11[] = new byte[inShort];
              inData.read(buf11, 0, inShort);
              units = new String(buf11);
              bytesRead += inShort;
            }

            // convert varnames to UC
            tempVar = tempVar.toUpperCase();

            // create new property
            tempProperties[p] = new JOAParameter(tempVar, units);

            // add this property to the section property list
            if (tempProperties[p].mUnits == null) {
              tempProperties[p].mUnits =
                  EPS_Util.paramNameToJOAUnits(false, tempProperties[0].mVarLabel);
            }

            if (tempProperties[p].mUnits == null) {
              tempProperties[p].mUnits = new String("na");
            }
            tempProperties[p].mCastOrObs = EPSConstants.ALL_OBS;

            // read the actual scale
            int actScale = inData.readShort();
            bytesRead += 2;
            if (actScale != 0) tempProperties[p].mActScale = 1.0 / (double) actScale;
            else tempProperties[p].mActScale = 1.0;

            // read the actual origin
            int actOrigin = inData.readShort();
            tempProperties[p].mActOrigin = (double) actOrigin * tempProperties[p].mActScale;

            // read reverse y
            int reverseY = inData.readShort();
            bytesRead += 2;
            if (reverseY == 0) tempProperties[p].mReverseY = false;
            else tempProperties[p].mReverseY = true;

            tempProperties[p].mWasCalculated = false;
          }
        }

        // read the cast headers
        for (int c = 0; c < numCasts; c++) {
          // read station number
          inShort = inData.readShort();
          bytesRead += 2;
          byte bufx[] = new byte[inShort];
          inData.read(bufx, 0, inShort);
          String stnNum = new String(bufx);
          bytesRead += inShort;

          // read cast number
          int castNum = inData.readShort();
          bytesRead += 2;

          double myLat = 0.0;
          double myLon = 0.0;
          if (vers == 2) {
            // read latitude/lon
            int lat = inData.readInt();
            bytesRead += 4;

            int lon = inData.readInt();
            bytesRead += 4;

            myLat = lat * 0.001;
            myLon = lon * 0.001;
          } else if (vers > 2) {
            // read latitude/lon
            myLat = inData.readDouble();
            bytesRead += 8;

            myLon = inData.readDouble();
            bytesRead += 4;
          }

          // read number of bottles
          int numBottles = inData.readShort();
          bytesRead += 2;

          // read the date
          int year = inData.readInt();
          bytesRead += 4;
          int month = inData.readInt();
          bytesRead += 4;
          int day = inData.readInt();
          bytesRead += 4;
          int hour = inData.readInt();
          bytesRead += 4;
          double min = inData.readDouble();
          bytesRead += 8;

          // read bottom
          int bottomdbar = inData.readInt();

          // read station quality
          int stnQual = inData.readShort();
          bytesRead += 2;

          ord++;
          JOAStation sh =
              new JOAStation(
                  ord,
                  shipCode,
                  stnNum,
                  castNum,
                  myLat,
                  myLon,
                  numBottles,
                  year,
                  month,
                  day,
                  hour,
                  min,
                  bottomdbar,
                  stnQual);
          sech.mStations.addElement(sh);
          sh.setType("JOA BOTTLE");

          // make a DBase object
          Dbase db = new Dbase();

          // add the global attributes
          db.addEPSAttribute(
              "CRUISE", EPCHAR, sech.mSectionDescription.length(), sech.mSectionDescription);
          db.addEPSAttribute("CAST", EPCHAR, sh.mStnNum.length(), sh.mStnNum);
          sarray[0] = (short) sh.mBottomDepthInDBARS;
          db.addEPSAttribute("WATER_DEPTH", EPSHORT, 1, sarray);
          db.addEPSAttribute("DATA_ORIGIN", EPCHAR, sech.mShipCode.length(), sech.mShipCode);
          String dType = sh.getType();
          if (dType == null) dType = "UNKN";
          db.addEPSAttribute("DATA_TYPE", EPCHAR, dType.length(), dType);
          sarray[0] = (short) stnQual;
          db.addEPSAttribute("STN_QUALITY", EPSHORT, 1, sarray);
          db.setDataType("JOA BOTTLE");

          // add to temporary collection
          dBases.addElement(db);
        }

        int start = mTotalStns;
        int end = sech.mStations.size() + mTotalStns;
        for (int sc = start; sc < end; sc++) {
          mProgress.setPercentComplete(100.0 * ((double) bytesRead / (double) bytesInFile));

          // get a dBase
          Dbase db = (Dbase) dBases.elementAt(sc);

          // get a station
          JOAStation sh = (JOAStation) sech.mStations.elementAt(sc - start);

          // create an array of arrays to store the data
          double[][] va = new double[sech.mNumVars][sh.mNumBottles];
          int[][] qc = new int[sech.mNumVars][sh.mNumBottles];
          short[] bqc = new short[sh.mNumBottles];
          int presPos = 0;

          // read the bottles
          for (int b = 0; b < sh.mNumBottles; b++) {
            // read the bottle quality code
            bqc[b] = inData.readShort();
            bytesRead += 2;

            for (int v = 0; v < sech.mNumVars; v++) {
              // store the position of the PRES variable
              if (tempProperties[v].mVarLabel.equals("PRES")) presPos = v;

              // get the measured parameter
              double dVarVal = EPSConstants.MISSINGVALUE;
              try {
                dVarVal = inData.readDouble();
              } catch (IOException e) {
                FileImportException fiex = new FileImportException();
                String errStr =
                    "Error reading the parameter data. "
                        + "\n"
                        + "Bottle #"
                        + b
                        + " Parameter #"
                        + v;
                fiex.setErrorType(errStr);
                throw fiex;
              }
              bytesRead += 8;

              // store the value in the multidimensional array
              va[v][b] = dVarVal;

              // get the quality flag
              short flag = (short) EPSConstants.MISSINGVALUE;

              try {
                flag = inData.readShort();
              } catch (IOException e) {
                FileImportException fiex = new FileImportException();
                String errStr =
                    "Error reading the parameter quality code. "
                        + "\n"
                        + "Bottle #"
                        + b
                        + " Parameter #"
                        + v;
                fiex.setErrorType(errStr);
                throw fiex;
              }
              bytesRead += 2;
              qc[v][b] = flag;
            } // for v
          } // for b

          // add the bottle quality codes as an attribute
          db.addEPSAttribute("BOTTLE_QUALITY_CODES", EPSHORT, sh.mNumBottles, bqc);

          // create the axes time = 0, depth = 1, lat = 2, lon = 3
          Axis timeAxis = new Axis();
          Axis zAxis = new Axis();
          Axis latAxis = new Axis();
          Axis lonAxis = new Axis();

          // time axis
          timeAxis.setName("time");
          timeAxis.setTime(true);
          timeAxis.setUnlimited(false);
          timeAxis.setAxisType(EPTAXIS);
          timeAxis.setLen(1);

          int hour = 0;
          if (sh.mHour != EPSConstants.MISSINGVALUE) hour = sh.mHour;

          double mins = 0;
          if (sh.mMinute != EPSConstants.MISSINGVALUE) mins = sh.mMinute;

          // make the time axis units
          String date = "days since ";
          int min = (int) mins;
          double fmin = mins - min;
          int secs = (int) (fmin * 60.0);
          double fsec = (fmin * 60.0) - secs;
          int msec = (int) (fsec * 1000.0);
          String fs = String.valueOf(fsec);
          fs = fs.substring(fs.indexOf(".") + 1, fs.length()).trim();
          int f = 0;
          if (fs != null && fs.length() > 0) f = Integer.valueOf(fs).intValue();

          // sprintf(time_string,"%04d-%02d-%02d %02d:%02d:%02d.%03d",yr,mon,day,hr,min,sec,f);
          String frmt =
              new String(
                  "{0,number,####}-{1,number,00}-{2,number,00} {3,number,00}:{4,number,00}:{5,number,00}.{6,number,000}");
          MessageFormat msgf = new MessageFormat(frmt);

          Object[] objs = {
            new Integer(sh.mYear),
            new Integer(sh.mMonth),
            new Integer(sh.mDay),
            new Integer(hour),
            new Integer(min),
            new Integer(secs),
            new Integer(f)
          };
          StringBuffer out = new StringBuffer();
          msgf.format(objs, out, null);
          String time_string = new String(out);
          date = date + time_string;
          timeAxis.addAttribute(0, "units", EPCHAR, date.length(), date);
          timeAxis.setUnits(date);
          GeoDate gd = null;
          try {
            gd = new GeoDate(sh.mMonth, sh.mDay, sh.mYear, hour, min, secs, msec);
            GeoDate[] ta = {gd};
            MultiArray tma = new ArrayMultiArray(ta);

            timeAxis.setData(tma);
            db.setAxis(timeAxis);
          } catch (Exception ex) {
            GeoDate[] ta = {new GeoDate()};
            MultiArray tma = new ArrayMultiArray(ta);

            timeAxis.setData(tma);
            db.setAxis(timeAxis);
          }

          // add the time axes variable
          EPSVariable var = new EPSVariable();
          var.setOname("time");
          var.setDtype(EPDOUBLE);
          var.setVclass(Double.TYPE);
          var.addAttribute(0, "units", EPCHAR, date.length(), date);
          var.setUnits(date);
          double[] vta = {0.0};
          MultiArray vtma = new ArrayMultiArray(vta);
          try {
            var.setData(vtma);
          } catch (Exception ex) {
          }
          db.addEPSVariable(var);

          // z axis
          zAxis.setName("depth");
          zAxis.setTime(false);
          zAxis.setUnlimited(false);
          zAxis.setLen(sh.mNumBottles);
          zAxis.setAxisType(EPZAXIS);
          zAxis.addAttribute(0, "FORTRAN_format", EPCHAR, 5, "f10.1");
          zAxis.addAttribute(1, "units", EPCHAR, 4, "dbar");
          zAxis.setUnits("dbar");
          zAxis.setFrmt("f10.1");
          // zAxis.addAttribute(2, "type", EPCHAR, 0, "");
          sarray[0] = 1;
          zAxis.addAttribute(2, "epic_code", EPSHORT, 1, sarray);
          double[] za = new double[sh.mNumBottles];
          for (int b = 0; b < sh.mNumBottles; b++) {
            za[b] = va[presPos][b];
          }
          MultiArray zma = new ArrayMultiArray(za);
          zAxis.setData(zma);
          db.setAxis(zAxis);

          // add the z axes variables
          var = new EPSVariable();
          var.setOname("depth");
          var.setDtype(EPDOUBLE);
          var.setVclass(Double.TYPE);
          var.addAttribute(0, "FORTRAN_format", EPCHAR, 5, "f10.1");
          var.addAttribute(1, "units", EPCHAR, 4, "dbar");
          var.setUnits("dbar");
          var.setFrmt("f10.1");
          // var.addAttribute(2, "type", EPCHAR, 0, "");
          sarray[0] = 1;
          var.addAttribute(2, "epic_code", EPSHORT, 1, sarray);
          MultiArray zvma = new ArrayMultiArray(za);
          try {
            var.setData(zvma);
          } catch (Exception ex) {
          }
          db.addEPSVariable(var);

          // lat axis
          latAxis.setName("latitude");
          latAxis.setTime(false);
          latAxis.setUnlimited(false);
          latAxis.setLen(1);
          latAxis.setAxisType(EPYAXIS);
          latAxis.addAttribute(0, "FORTRAN_format", EPCHAR, 5, "f10.4");
          latAxis.addAttribute(1, "units", EPCHAR, 7, "degrees");
          latAxis.setUnits("degrees");
          latAxis.setFrmt("f10.4");
          // latAxis.addAttribute(2, "type", EPCHAR, 0, "");
          sarray[0] = 500;
          latAxis.addAttribute(2, "epic_code", EPSHORT, 1, sarray);
          double lat = sh.mLat;
          double[] la = {lat};
          MultiArray lma = new ArrayMultiArray(la);
          latAxis.setData(lma);
          db.setAxis(latAxis);

          // add the y axes variable
          var = new EPSVariable();
          var.setOname("latitude");
          var.setDtype(EPDOUBLE);
          var.setVclass(Double.TYPE);
          var.addAttribute(0, "FORTRAN_format", EPCHAR, 5, "f10.4");
          var.addAttribute(1, "units", EPCHAR, 7, "degrees");
          var.setUnits("degrees");
          var.setFrmt("f10.4");
          // var.addAttribute(2, "type", EPCHAR, 0, "");
          sarray[0] = 500;
          var.addAttribute(2, "epic_code", EPSHORT, 1, sarray);
          MultiArray yvma = new ArrayMultiArray(la);
          try {
            var.setData(yvma);
          } catch (Exception ex) {
          }
          db.addEPSVariable(var);

          // lon axis
          lonAxis.setName("longitude");
          lonAxis.setTime(false);
          lonAxis.setUnlimited(false);
          lonAxis.setLen(1);
          lonAxis.setAxisType(EPXAXIS);
          lonAxis.addAttribute(0, "FORTRAN_format", EPCHAR, 5, "f10.4");
          lonAxis.addAttribute(1, "units", EPCHAR, 7, "degrees");
          lonAxis.setUnits("degrees");
          lonAxis.setFrmt("f10.4");
          // lonAxis.addAttribute(2, "type", EPCHAR, 0, "");
          sarray[0] = 502;
          lonAxis.addAttribute(2, "epic_code", EPSHORT, 1, sarray);
          double lon = sh.mLon;
          double[] lla = {lon};
          lma = new ArrayMultiArray(lla);
          lonAxis.setData(lma);
          db.setAxis(lonAxis);

          // add the x axes variable
          var = new EPSVariable();
          var.setOname("longitude");
          var.setDtype(EPDOUBLE);
          var.setVclass(Double.TYPE);
          var.addAttribute(0, "FORTRAN_format", EPCHAR, 5, "f10.4");
          var.addAttribute(1, "units", EPCHAR, 7, "degrees");
          var.setUnits("degrees");
          var.setFrmt("f10.4");
          // var.addAttribute(2, "type", EPCHAR, 0, "");
          sarray[0] = 502;
          var.addAttribute(2, "epic_code", EPSHORT, 1, sarray);
          MultiArray xvma = new ArrayMultiArray(lla);
          try {
            var.setData(xvma);
          } catch (Exception ex) {
          }

          db.addEPSVariable(var);

          // add the measured variables
          for (int v = 0; v < sech.mNumVars; v++) {
            // if (presPos == v)
            //	continue;

            // create an array of measured EPSVariables for this database
            EPSVariable epsVar = new EPSVariable();

            // initialize the new EPSVariables
            // look this variable up in JOA EPIC_Key. find matching entry in original EPIC Key
            String oname = tempProperties[v].mVarLabel;
            String sname = null;
            String lname = null;
            String gname = null;
            String units = null;
            String ffrmt = null;
            int keyID = -99;
            int type = -99;
            try {
              keyID = mEpicKeyDB.findKey(tempProperties[v].mVarLabel);
              Key key = mOrigEpicKeyDB.findKey(keyID);
              gname = key.getGname();
              sname = key.getSname();
              lname = key.getLname();
              units = key.getUnits();
              ffrmt = key.getFrmt();
              type = key.getType();
            } catch (Exception e) {
              lname = tempProperties[v].mVarLabel;
              gname = tempProperties[v].mVarLabel;
              sname = tempProperties[v].mVarLabel;
              units = tempProperties[v].mUnits;
            }

            // make a new variable
            epsVar = new EPSVariable();

            epsVar.setOname(oname);
            epsVar.setSname(sname);
            epsVar.setLname(lname);
            epsVar.setGname(gname);
            epsVar.setDtype(EPDOUBLE);
            epsVar.setVclass(Double.TYPE);
            int numAttributes = 0;
            if (ffrmt != null) {
              epsVar.addAttribute(numAttributes++, "FORTRAN_format", EPCHAR, ffrmt.length(), ffrmt);
              epsVar.setFrmt(ffrmt);
            }
            if (units != null && units.length() > 0) {
              epsVar.addAttribute(numAttributes++, "units", EPCHAR, units.length(), units);
              epsVar.setUnits(units);
            }
            if (keyID >= 0) {
              sarray[0] = (short) type;
              // epsVar.addAttribute(numAttributes++, "type", EPSHORT, 1, sarray);
            }
            if (keyID >= 0) {
              sarray[0] = (short) keyID;
              epsVar.addAttribute(numAttributes++, "epic_code", EPSHORT, 1, sarray);
            }

            // add the quality code attribute
            String qcVar = oname + "_QC";
            epsVar.addAttribute(numAttributes++, "OBS_QC_VARIABLE", EPCHAR, qcVar.length(), qcVar);

            // connect variable to axis
            epsVar.setDimorder(0, 0);
            epsVar.setDimorder(1, 1);
            epsVar.setDimorder(2, 2);
            epsVar.setDimorder(3, 3);
            epsVar.setT(timeAxis);
            epsVar.setZ(zAxis);
            epsVar.setY(latAxis);
            epsVar.setX(lonAxis);

            // set the data
            // create storage for the measured variables
            double[][][][] vaa = new double[1][sh.mNumBottles][1][1];
            for (int b = 0; b < sh.mNumBottles; b++) {
              vaa[0][b][0][0] = va[v][b];
            }
            MultiArray mdma = new ArrayMultiArray(vaa);
            try {
              epsVar.setData(mdma);
            } catch (Exception ex) {
              System.out.println("throwing");
            }

            // add the variable to the database
            db.addEPSVariable(epsVar);

            // create the quality code variable
            epsVar = new EPSVariable();
            epsVar.setOname(oname + "_QC");
            epsVar.setSname(sname + "_QC");
            epsVar.setLname(sname + "_QC");
            epsVar.setGname(sname + "_QC");
            epsVar.setDtype(EPSHORT);
            epsVar.setVclass(Short.TYPE);

            // connect variable to axis
            epsVar.setDimorder(0, 0);
            epsVar.setDimorder(1, 1);
            epsVar.setDimorder(2, 2);
            epsVar.setDimorder(3, 3);
            epsVar.setT(timeAxis);
            epsVar.setZ(zAxis);
            epsVar.setY(latAxis);
            epsVar.setX(lonAxis);

            // set the data
            // create storage for the qc variables
            short[][][][] qcaa = new short[1][sh.mNumBottles][1][1];
            for (int b = 0; b < sh.mNumBottles; b++) {
              qcaa[0][b][0][0] = (short) qc[v][b];
            }
            MultiArray qcma = new ArrayMultiArray(qcaa);
            try {
              epsVar.setData(qcma);
            } catch (Exception ex) {
              System.out.println("throwing");
            }

            // add the qc variable to the database
            db.addEPSVariable(epsVar);
          } // for v
        }
        mTotalStns += numCasts;
      } // for sc

      // read the file comments
      StringBuffer sb = null;
      while (true) {
        try {
          // read continuation line
          inShort = inData.readShort();
          bytesRead += 2;

          if (inShort == 1) {
            // read number of bytes in file description string
            inShort = inData.readShort();
            bytesRead += 2;

            // read the file description String
            byte buf2[] = new byte[inShort];
            inData.read(buf2, 0, inShort);
            String commentLine = new String(buf2);
            bytesRead += inShort;

            if (sb == null) sb = new StringBuffer(commentLine);
            else sb.append(commentLine);
          }
        } catch (IOException e) {
          break;
        }
      } // while true

      if (sb != null) {
        // make attributes for the comments
        mOwnerDBase.setDataComment(new String(sb));
      }

      // make a sub database in the dbase
      mOwnerDBase.createSubEntries(mTotalStns, mFile.getName());
      for (int d = 0; d < mTotalStns; d++) {
        Dbase db = (Dbase) dBases.elementAt(d);
        mOwnerDBase.addSubEntry(db);
      }
      mProgress.setPercentComplete(100.0);
      mProgress.setVisible(false);
      mProgress.dispose();
      in.close();
    } catch (IOException e) {
      mProgress.setVisible(false);
      mProgress.dispose();
      throw e;
    }
  }