Пример #1
0
  /** Reads the suite settings from storage. */
  private void readSettings() {
    byte[] maximums = Permissions.getEmptySet();
    byte[] currentLevels = Permissions.getEmptySet();
    RandomAccessStream storage = new RandomAccessStream(classSecurityToken);
    DataInputStream storageStream;
    int version;
    int count;

    permissions = new byte[2][];
    permissions[Permissions.MAX_LEVELS] = maximums;
    permissions[Permissions.CUR_LEVELS] = currentLevels;

    try {
      storage.connect(getStorageRoot() + Installer.SETTINGS_FILENAME, Connector.READ);
      try {
        storageStream = storage.openDataInputStream();

        version = storageStream.readByte();
        /*
         * only version 1 are handled by the method
         * 0 means that this is a beta version that are not handled
         * by the method. Note that version number only has to
         * increase if data has been removed, not if new data has been
         * added to the end of the file.
         */
        if (version != 1) {
          System.out.println("Corrupt application settings file.");
          return;
        }

        trusted = storageStream.readBoolean();

        pushInterruptSetting = storageStream.readByte();

        count = storageStream.readByte();
        storageStream.readFully(currentLevels, 0, count);

        count = storageStream.readByte();
        storageStream.readFully(maximums, 0, count);
      } finally {
        storage.disconnect();
      }
    } catch (IOException e) {
      // ignore, old settings files are shorter
    }
  }
Пример #2
0
 public MessageRunnable(int msz, int mtp, DataInputStream di)
     throws IOException, SocketException {
   msgsize = msz;
   msgtype = mtp;
   msgbytes = new byte[msgsize - 2];
   di.readFully(msgbytes);
   // di.read(msgbytes);
   din = new DataInputStream(new ByteArrayInputStream(msgbytes));
 }
Пример #3
0
 /** Read the contents of a file. */
 String read(File f) throws IOException {
   byte[] bytes = new byte[(int) f.length()];
   DataInputStream in = new DataInputStream(new FileInputStream(f));
   try {
     in.readFully(bytes);
   } finally {
     in.close();
   }
   return new String(bytes);
 }
Пример #4
0
  public static void main(String[] args) throws JsonParseException, IOException {
    byte[] tAuctHist = null;
    byte[] tAuctHist1 = null;
    try {
      File tAuctHistFile = new File("/tmp/tauctHist.json");
      File tAuctHistFile1 = new File("/tmp/tauctHist1.json");
      tAuctHist = new byte[(int) tAuctHistFile.length()];
      tAuctHist1 = new byte[(int) tAuctHistFile1.length()];
      DataInputStream dis = new DataInputStream(new FileInputStream(tAuctHistFile));
      dis.readFully(tAuctHist);
      dis.close();

      dis = new DataInputStream(new FileInputStream(tAuctHistFile1));
      dis.readFully(tAuctHist1);
      dis.close();
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    HashMap<String, StatsCounter> auctMap = fromJson(tAuctHist);
    System.out.println(MinprocParser.getAuctHistAsJsonString(auctMap));
  }
Пример #5
0
  public Blob(DataInputStream in, Scene theScene) throws IOException, InvalidObjectException {
    super(in, theScene);

    int version = in.readInt();
    if (version != VERSION) {
      throw new InvalidObjectException("Unsupported object version: " + version);
    }

    // Hardness.
    setPropertyValue(0, in.readDouble());

    // setNamePositive.
    int len = in.readInt();
    byte[] str = new byte[len];
    in.readFully(str);
    setPropertyValue(1, new String(str));

    // setNameNegative.
    len = in.readInt();
    str = new byte[len];
    in.readFully(str);
    setPropertyValue(2, new String(str));
  }
Пример #6
0
 protected byte[] getJarEntryBytes(JarFile jarFile, JarEntry je) throws IOException {
   DataInputStream dis = null;
   byte[] jeBytes = null;
   try {
     long lSize = je.getSize();
     if (lSize <= 0 || lSize >= Integer.MAX_VALUE) {
       throw new IllegalArgumentException(
           "Size [" + lSize + "] not valid for war entry [" + je + "]");
     }
     jeBytes = new byte[(int) lSize];
     InputStream is = jarFile.getInputStream(je);
     dis = new DataInputStream(is);
     dis.readFully(jeBytes);
   } finally {
     if (dis != null) dis.close();
   }
   return jeBytes;
 }
Пример #7
0
 /**
  * Send a plugin JAR file to the client
  *
  * @param data the plugin name
  */
 private void sendPlugin(ObjectConnection oc, String data) {
   DataInputStream dis = null;
   try {
     dis = new DataInputStream(new FileInputStream(APPLICATIONS_DIRECTORY + data + ".jar"));
     byte[] buf = new byte[dis.available()];
     dis.readFully(buf);
     oc.write(buf);
   } catch (Exception e) {
     Logging.getLogger().warning("Unable to send the file: " + data + ".jar");
   } finally {
     if (dis != null) {
       try {
         dis.close();
       } catch (IOException ioe) {
       }
     }
   }
 }
 byte[] download(File f) {
   if (!f.exists()) {
     IJ.error("Plugin Installer", "File not found: " + f);
     return null;
   }
   byte[] data = null;
   try {
     int len = (int) f.length();
     InputStream in = new BufferedInputStream(new FileInputStream(f));
     DataInputStream dis = new DataInputStream(in);
     data = new byte[len];
     dis.readFully(data);
     dis.close();
   } catch (Exception e) {
     IJ.error("Plugin Installer", "" + e);
     data = null;
   }
   return data;
 }
Пример #9
0
 @SuppressWarnings("ThrowFromFinallyBlock")
 private byte[] getFileBytes(File classFile) throws IOException {
   DataInputStream dis = null;
   byte[] jeBytes = null;
   try {
     long lSize = classFile.length();
     if (lSize <= 0 || lSize >= Integer.MAX_VALUE) {
       throw new IllegalArgumentException(
           "Size [" + lSize + "] not valid for classpath file [" + classFile + "]");
     }
     jeBytes = new byte[(int) lSize];
     InputStream is = new FileInputStream(classFile);
     dis = new DataInputStream(is);
     dis.readFully(jeBytes);
   } finally {
     if (dis != null) dis.close();
   }
   return jeBytes;
 }
Пример #10
0
  public void run() {
    String objRouter = applet.getParameter("name");
    // No Internationalisation
    try {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      DataOutputStream outp = new DataOutputStream(byteStream);
      outp.writeInt(GenericConstants.ROUTER_PROPERTIES);
      outp.writeUTF(objRouter);
      outp.flush();

      byte[] bytes = byteStream.toByteArray();
      outp.close();
      byteStream.reset();
      byteStream.close();
      byte[] data = GenericSession.getInstance().syncSend(bytes);
      if (data != null) {
        DataInputStream inp = new DataInputStream(new ByteArrayInputStream(data));
        int reqId = inp.readInt();
        if (reqId == GenericConstants.ROUTER_PROPERTIES) {
          int length = inp.readInt();
          byte serverData[] = new byte[length];
          inp.readFully(serverData);
          routerobject = NmsClientUtil.deSerializeVector(serverData);
        }

        init();
        refresh();
        super.setVisible(true);
      }
      /*init();
      refresh();
      super.setVisible(true);*/

      else close();

    } catch (Exception e) {
      // NmsClientUtil.err(NmsClientUtil.getFrame(app),"IO Error sending request to server.
      // "+e);//No Internationalisation
    }
  }
Пример #11
0
  /** Internal method. Get and check response packet from searchd. */
  private byte[] _GetResponse(Socket sock) {
    /* connect */
    DataInputStream sIn = null;
    InputStream SockInput = null;
    try {
      SockInput = sock.getInputStream();
      sIn = new DataInputStream(SockInput);

    } catch (IOException e) {
      _error = "getInputStream() failed: " + e;
      return null;
    }

    /* read response */
    byte[] response = null;
    short status = 0, ver = 0;
    int len = 0;
    try {
      /* read status fields */
      status = sIn.readShort();
      ver = sIn.readShort();
      len = sIn.readInt();

      /* read response if non-empty */
      if (len <= 0) {
        _error = "invalid response packet size (len=" + len + ")";
        return null;
      }

      response = new byte[len];
      sIn.readFully(response, 0, len);

      /* check status */
      if (status == SEARCHD_WARNING) {
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(response));

        int iWarnLen = in.readInt();
        _warning = new String(response, 4, iWarnLen);

        System.arraycopy(response, 4 + iWarnLen, response, 0, response.length - 4 - iWarnLen);

      } else if (status == SEARCHD_ERROR) {
        _error = "searchd error: " + new String(response, 4, response.length - 4);
        return null;

      } else if (status == SEARCHD_RETRY) {
        _error = "temporary searchd error: " + new String(response, 4, response.length - 4);
        return null;

      } else if (status != SEARCHD_OK) {
        _error = "searched returned unknown status, code=" + status;
        return null;
      }

    } catch (IOException e) {
      if (len != 0) {
        /* get trace, to provide even more failure details */
        PrintWriter ew = new PrintWriter(new StringWriter());
        e.printStackTrace(ew);
        ew.flush();
        ew.close();
        String sTrace = ew.toString();

        /* build error message */
        _error =
            "failed to read searchd response (status="
                + status
                + ", ver="
                + ver
                + ", len="
                + len
                + ", trace="
                + sTrace
                + ")";
      } else {
        _error = "received zero-sized searchd response (searchd crashed?): " + e.getMessage();
      }
      return null;

    } finally {
      if (_socket == null) {
        try {
          if (sIn != null) sIn.close();
          if (sock != null && !sock.isConnected()) sock.close();
        } catch (IOException e) {
          /* silently ignore close failures; nothing could be done anyway */
        }
      }
    }

    return response;
  }
Пример #12
0
 /** Internal method. String IO helper. */
 private static String readNetUTF8(DataInputStream istream) throws IOException {
   int iLen = istream.readInt();
   byte[] sBytes = new byte[iLen];
   istream.readFully(sBytes);
   return new String(sBytes, "UTF-8");
 }
Пример #13
0
  /**
   * Gets properites from a symbolically named installed package. The properties are the attributes
   * in the application descriptor and JAR Manifest.
   */
  private void getPropertiesFromStorage() {
    RandomAccessStream myStorage;
    int size;
    byte[] buffer;
    InputStream is;
    DataInputStream dis;
    String jadEncoding = null;

    myStorage = new RandomAccessStream(classSecurityToken);

    // Get the JAD encoding, if the server provided one
    try {
      myStorage.connect(storageRoot + Installer.JAD_ENCODING_FILENAME, Connector.READ);
      try {
        // convert the JAD encoding to UTF8 and write it to storage
        dis = myStorage.openDataInputStream();
        try {
          jadEncoding = dis.readUTF();
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // servers can choose the default encoding by not providing one
    }

    // Load .jad file
    bufferedJadProps = new JadProperties();
    try {
      myStorage.connect(storageRoot + Installer.JAD_FILENAME, Connector.READ);
      try {
        size = myStorage.getSizeOf();
        buffer = new byte[size];
        dis = myStorage.openDataInputStream();
        try {
          dis.readFully(buffer);
          is = new ByteArrayInputStream(buffer);

          bufferedJadProps.load(is, jadEncoding);

          buffer = null;
          is = null;
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // Jar only install
    }

    try {
      // Get Manifest file so we can buffer it
      myStorage.connect(storageRoot + Installer.MANIFEST_FILENAME, Connector.READ);
      try {
        size = myStorage.getSizeOf();
        buffer = new byte[size];
        dis = myStorage.openDataInputStream();
        try {
          dis.readFully(buffer);
          is = new ByteArrayInputStream(buffer);

          bufferedJarProps = new ManifestProperties();
          bufferedJarProps.load(is);

          buffer = null;
          is = null;
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // ignore
    }
  }