Beispiel #1
0
 public boolean isForSale(String s) throws SQLException, Exception {
   if (tempCache != null && tempCache.Name().equals(s)) {
     // has been retrieved recently
     return tempCache.sell >= 0;
   }
   // if itemExists, tempCache will contain the item
   return itemExists(s) && tempCache.sell >= 0; // getSellPrice(s) >= 0;
 }
Beispiel #2
0
 public boolean canBuy(String s) throws SQLException, Exception {
   if (tempCache != null && tempCache.Name().equals(s)) {
     // has been retrieved recently
     return tempCache.buy >= 0;
   }
   // if itemExists, tempCache will contain the item
   return itemExists(s) && tempCache.buy >= 0;
 }
Beispiel #3
0
  public boolean saveFile(File tosave) throws IOException {
    if (tosave != null && !tosave.isDirectory()) {
      if (!tosave.exists()) {
        File dir =
            new File(
                tosave
                    .getAbsolutePath()
                    .substring(0, tosave.getAbsolutePath().lastIndexOf(File.separatorChar)));
        dir.mkdirs();
        try {
          if (!tosave.createNewFile()) {
            return false;
          }
        } catch (Exception e) {
          return false;
        }
      }
      if (tosave.canWrite()) {

        FileWriter fstream = null;
        try {
          fstream = new FileWriter(tosave.getAbsolutePath());
          // System.out.println("writing to " + tosave.getAbsolutePath());
          BufferedWriter out = new BufferedWriter(fstream);
          out.write("id,subdata,buyprice,sellprice,name");
          out.newLine();
          for (PriceListItem i : priceList) {
            // names provided for others to easily edit db
            // out.write(i.ID() + "," + i.Data() + "," + i.buy + "," + i.sell + "," + i.Name());
            out.write(
                String.format(
                    Locale.US, "%d,%d,%.2f,%.2f,%s", i.ID(), i.Data(), i.buy, i.sell, i.Name()));
            out.newLine();
          }
          out.flush();
          out.close();
        } catch (IOException ex) {
          if (!log_nothrow) {
            throw new IOException("Error opening " + tosave.getName() + " for writing", ex);
          }
          logger.log(Level.SEVERE, "Error opening " + tosave.getName() + " for writing", ex);
        } finally {
          if (fstream != null) {
            try {
              fstream.close();
            } catch (IOException ex) {
              /*
              if (!log_nothrow) {
              throw new IOException("Error closing " + tosave.getName(), ex);
              }
              logger.log(Level.SEVERE, "Error closing " + tosave.getName(), ex);*/

            }
          }
        }
        return true;
      }
    } else if (tosave == null) {
      throw new IOException("no file to save to");
    } else if (tosave.isDirectory()) {
      throw new IOException("file to save is a directory");
    }
    return false;
  }