コード例 #1
0
ファイル: ParamerSet.java プロジェクト: hdwt8289/SerialSlave1
 private BasicProcessImage getModscanProcessImage(int slaveId, Map map, DBCollection coll) {
   BasicProcessImage processImage = new BasicProcessImage(slaveId);
   processImage.setAllowInvalidAddress(true);
   processImage.setInvalidAddressValue(Short.valueOf("0"));
   // Add an image listener.
   processImage.addListener(new BasicProcessImageListener());
   return processImage;
 }
コード例 #2
0
  /**
   * Create a new reader.
   *
   * @param in the input
   * @param out the output
   * @param bindings the key bindings to use
   * @param term the terminal to use
   */
  public ConsoleReader(InputStream in, Writer out, InputStream bindings, Terminal term)
      throws IOException {
    this.terminal = term;
    setInput(in);
    this.out = out;

    if (bindings == null) {
      try {
        String bindingFile =
            System.getProperty(
                "jline.keybindings",
                new File(System.getProperty("user.home", ".jlinebindings.properties"))
                    .getAbsolutePath());

        if (new File(bindingFile).isFile()) {
          bindings = new FileInputStream(new File(bindingFile));
        }
      } catch (Exception e) {
        // swallow exceptions with option debugging
        if (debugger != null) {
          e.printStackTrace(debugger);
        }
      }
    }

    if (bindings == null) {
      bindings = terminal.getDefaultBindings();
    }

    this.keybindings = new short[Character.MAX_VALUE * 2];

    Arrays.fill(this.keybindings, UNKNOWN);

    /**
     * Loads the key bindings. Bindings file is in the format:
     *
     * <p>keycode: operation name
     */
    if (bindings != null) {
      Properties p = new Properties();
      p.load(bindings);
      bindings.close();

      for (Iterator i = p.keySet().iterator(); i.hasNext(); ) {
        String val = (String) i.next();

        try {
          Short code = new Short(val);
          String op = (String) p.getProperty(val);

          Short opval = (Short) KEYMAP_NAMES.get(op);

          if (opval != null) {
            keybindings[code.shortValue()] = opval.shortValue();
          }
        } catch (NumberFormatException nfe) {
          consumeException(nfe);
        }
      }

      // hardwired arrow key bindings
      // keybindings[VK_UP] = PREV_HISTORY;
      // keybindings[VK_DOWN] = NEXT_HISTORY;
      // keybindings[VK_LEFT] = PREV_CHAR;
      // keybindings[VK_RIGHT] = NEXT_CHAR;
    }
  }
コード例 #3
0
ファイル: DCRaw.java プロジェクト: Yuniks/LightZone
  private static ImageData readPPM(File file) throws IOException, BadImageFileException {
    FileInputStream s = new FileInputStream(file);

    ImageData imageData;
    try {
      String S1 = readln(s);

      int width;
      int height;
      int bands;
      int dataType;
      if (S1.equals("P5") || S1.equals("P6")) {
        bands = S1.equals("P5") ? 1 : 3;
        String S2 = readln(s);
        String S3 = readln(s);

        String dimensions[] = S2.split("\\s");
        width = Integer.parseInt(dimensions[0]);
        height = Integer.parseInt(dimensions[1]);

        dataType = S3.equals("255") ? DataBuffer.TYPE_BYTE : DataBuffer.TYPE_USHORT;

        imageData = new ImageData(width, height, bands, dataType);
      } else if (S1.equals("P7")) {
        String WIDTH = "WIDTH ";
        String HEIGHT = "HEIGHT ";
        String DEPTH = "DEPTH ";
        String MAXVAL = "MAXVAL ";
        // String TUPLTYPE = "TUPLTYPE ";
        // String ENDHDR = "ENDHDR";
        String SWIDTH = readln(s);
        width = Integer.parseInt(SWIDTH.substring(WIDTH.length()));
        String SHEIGHT = readln(s);
        height = Integer.parseInt(SHEIGHT.substring(HEIGHT.length()));
        String SDEPTH = readln(s);
        bands = Integer.parseInt(SDEPTH.substring(DEPTH.length()));
        String SMAXVAL = readln(s);
        dataType =
            SMAXVAL.substring(MAXVAL.length()).equals("65535")
                ? DataBuffer.TYPE_USHORT
                : DataBuffer.TYPE_BYTE;
        // String STUPLTYPE = readln(s);
        // String SENDHDR = readln(s);
        imageData = new ImageData(width, height, bands, dataType);
      } else return null;

      int totalData = width * height * bands * (dataType == DataBuffer.TYPE_BYTE ? 1 : 2);

      FileChannel c = s.getChannel();

      if (file.length() != totalData + c.position()) {
        c.close();
        throw new BadImageFileException(file);
      }

      ByteBuffer bb = c.map(FileChannel.MapMode.READ_ONLY, c.position(), totalData);

      if (dataType == DataBuffer.TYPE_USHORT) {
        // bb.order(ByteOrder.BIG_ENDIAN);
        bb.order(ByteOrder.nativeOrder());
        bb.asShortBuffer().get((short[]) imageData.data);

        // Darty hack to prevent crash on Arch Linux (issue #125)
        if (ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
          for (int i = 0; i < ((short[]) imageData.data).length; ++i)
            ((short[]) imageData.data)[i] = Short.reverseBytes(((short[]) imageData.data)[i]);
      } else bb.get((byte[]) imageData.data);

      if (bb instanceof DirectBuffer) ((DirectBuffer) bb).cleaner().clean();

      c.close();
    } catch (Exception e) {
      e.printStackTrace();
      s.close();
      throw new BadImageFileException(file, e);
    } finally {
      s.close();
    }

    return imageData;
  }