public static void writeArray(String s, int[] x) {
   try {
     RandomAccessFile output = new RandomAccessFile(s, "rw");
     for (int i = 0; i < x.length; i++) output.writeInt(x[i]);
   } catch (IOException e) {
     System.out.println(e.getMessage());
   }
 }
Exemplo n.º 2
0
  void doExeCommand() {
    JViewport viewport = scrollPane.getViewport();
    String strContent = new String();
    PSlider slider;
    int i;
    File fp = new File(dataFile);

    RandomAccessFile access = null;
    Runtime program = Runtime.getRuntime();
    String cmdTrigger = "trigger";

    boolean delete = fp.delete();

    try {
      fp.createNewFile();
    } catch (IOException ie) {
      System.err.println("Couldn't create the new file " + ie);
      // System.exit(-1);;
    }

    try {
      access = new RandomAccessFile(fp, "rw");
    } catch (IOException ie) {
      System.err.println("Error in accessing the file " + ie);
      // System.exit(-1);;
    }

    for (i = 0; i < COMPONENTS; i++) {
      slider = (PSlider) vSlider.elementAt(i);
      /* Modified on March 20th to satisfy advisors' new request */
      if (slider.isString == true) strContent = strContent + slider.getRealStringValue() + " ";
      else strContent = strContent + slider.getValue() + " ";
    }

    // Get value of the radio button group
    if (firstBox.isSelected() == true) strContent = strContent + "1";
    else strContent = strContent + "0";

    try {
      access.writeBytes(strContent);
      access.close();
    } catch (IOException ie) {
      System.err.println("Error in writing to file " + ie);
      // System.exit(-1);;
    }
    // Trigger the OpenGL program to update with new values
    try {
      Process pid = program.exec(cmdTrigger);
    } catch (IOException ie) {
      System.err.println("Couldn't run " + ie);
      // System.exit(-1);;
    }
    doSourceFileUpdate();
  }
 /* (non-Javadoc)
  * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
  */
 public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
   int ret = PAGE_EXISTS;
   String line = null;
   try {
     if (fph.knownPage(page)) {
       in.seek(fph.getFileOffset(page));
       line = in.readLine();
     } else {
       long offset = in.getFilePointer();
       line = in.readLine();
       if (line == null) {
         ret = NO_SUCH_PAGE;
       } else {
         fph.createPage(page);
         fph.setFileOffset(page, offset);
       }
     }
     if (ret == PAGE_EXISTS) {
       // Seite ausgeben, Grafikkontext vorbereiten
       Graphics2D g2 = (Graphics2D) g;
       g2.scale(1.0 / RESMUL, 1.0 / RESMUL);
       int ypos = (int) pf.getImageableY() * RESMUL;
       int xpos = ((int) pf.getImageableX() + 2) * RESMUL;
       int yd = 12 * RESMUL;
       int ymax = ypos + (int) pf.getImageableHeight() * RESMUL - yd;
       // Seitentitel ausgeben
       ypos += yd;
       g2.setColor(Color.black);
       g2.setFont(new Font("Monospaced", Font.BOLD, 10 * RESMUL));
       g.drawString(fbname + " Seite " + (page + 1), xpos, ypos);
       g.drawLine(
           xpos,
           ypos + 6 * RESMUL,
           xpos + (int) pf.getImageableWidth() * RESMUL,
           ypos + 6 * RESMUL);
       ypos += 2 * yd;
       // Zeilen ausgeben
       g2.setColor(new Color(0, 0, 127));
       g2.setFont(new Font("Monospaced", Font.PLAIN, 10 * RESMUL));
       while (line != null) {
         g.drawString(line, xpos, ypos);
         ypos += yd;
         if (ypos >= ymax) {
           break;
         }
         line = in.readLine();
       }
     }
   } catch (IOException e) {
     throw new PrinterException(e.toString());
   }
   return ret;
 }
  private void readPalette() {
    RandomAccessFile rIn = null;
    ByteBuffer buf = null;
    int i;
    try {
      if (paletteFile != null) {
        // see if the file exists, if not, set it to the default palette.
        File file = new File(paletteFile);

        numPaletteEntries = (int) (file.length() / 4);

        buf = ByteBuffer.allocate(numPaletteEntries * 4);

        rIn = new RandomAccessFile(paletteFile, "r");

        FileChannel inChannel = rIn.getChannel();

        inChannel.position(0);
        inChannel.read(buf);

        // Check the byte order.
        buf.order(ByteOrder.LITTLE_ENDIAN);

        buf.rewind();
        IntBuffer ib = buf.asIntBuffer();
        paletteData = new int[numPaletteEntries];
        ib.get(paletteData);
        ib = null;
      }

    } catch (Exception e) {
      System.err.println("Caught exception: " + e.toString());
      System.err.println(e.getStackTrace());
    } finally {
      if (rIn != null) {
        try {
          rIn.close();
        } catch (Exception e) {
        }
      }
    }
  }
  public My_Room_AC_db(String name) {
    y = new ArrayList<String>();

    try {
      raf = new RandomAccessFile("ac_db.dat", "r");
      String arr2[] = name.split("#");
      while (true) {
        String rec = raf.readUTF();
        String arr[] = rec.split("#");
        if (arr[0].equals(arr2[0])) {
          y.add(name);
        } else {
          y.add(rec);
        }
      }
    } catch (Exception ep) {
    } finally {
      try {
        // if(raf!=null)
        raf.close();
        File f = new File("ac_db.dat", "r");
        f.delete();
      } catch (Exception ex) {
      }
    }

    raf = null;
    try {
      raf = new RandomAccessFile("ac_db.dat", "rw");
      for (String ss : y) {
        raf.writeUTF(ss);
      }
    } catch (Exception ef) {
    } finally {
      try {
        raf.close();
      } catch (Exception ex) {
      }
    }
  }
  public static String readArray(String s) {
    String output = "[ ";
    boolean endOfFile = false;

    try {
      RandomAccessFile input = new RandomAccessFile(s, "rw");
      input.seek(0);

      while (!endOfFile) {
        try {
          output = output + input.readInt() + " ";
        } catch (EOFException e) {
          endOfFile = true;
          output = output + "]";
        }
      }
    } catch (IOException e) {
      return e.getMessage();
    }

    return output;
  }
Exemplo n.º 7
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    RandomAccessFile access = null;
    String tempFile = "temp" + round + ".html";
    File fp = new File(tempFile);
    boolean firstChoice = true;
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // round += 1;
    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      // System.exit(-1);;
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      // System.exit(-1);;
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      // System.exit(-1);;
    }
    // do the replacement.
    // First having to update the code part that is active in this section before
    // doing variables updated. Look at the current active radiobutton to make decision
    if (secondBox.isSelected() == true) firstChoice = false;
    if (firstChoice == true) {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr2);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr2 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr2.length(), tempStr);
      strContent = new String(strBuf);
    } else {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr1);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr1 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr1.length(), tempStr);
      strContent = new String(strBuf);
    }
    for (i = COMPONENTS; i > 0; i--) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i - 1);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "JPOT$" + i;
      // get the position of the search string in the content string.
      while ((posFound = strContent.indexOf(str1)) != -1) {
        strBuf = new StringBuffer(strContent);
        strBuf.replace(posFound, posFound + str1.length(), sliderValue);
        strContent = new String(strBuf);
      }
    }

    boolean delete = fp.delete();

    try {
      fp.createNewFile();
    } catch (IOException ie) {
      System.err.println("Couldn't create the new file " + ie);
      // System.exit(-1);;
    }

    try {
      access = new RandomAccessFile(fp, "rw");
    } catch (IOException ie) {
      System.err.println("Error in accessing the file " + ie);
      // System.exit(-1);;
    }

    try {
      access.writeBytes(strContent);
      access.close();
    } catch (IOException ie) {
      System.err.println("Error in writing to file " + ie);
      // System.exit(-1);;
    }
    try {
      textPane.getDocument().putProperty(Document.StreamDescriptionProperty, null);
      URL url = new URL("file:" + tempFile + "#gohere");
      textPane.setPage(url);
      delete = fp.delete();
    } catch (IOException ie) {
      System.err.println("Can not get the example html file " + ie);
      // System.exit(-1);;
    }
  }
 /**
  * Druckt die file.
  *
  * @throws PrinterException the printer exception
  * @throws IOException Signals that an I/O exception has occurred.
  */
 public void printFile() throws PrinterException, IOException {
   fph = new FilePrintHelper();
   in = new RandomAccessFile(schreibeTempDatei(), "r");
   pjob.print();
   in.close();
 }