示例#1
0
    InMemorySourceRepository(@WillClose ZipInputStream in) throws IOException {
      try {
        while (true) {

          ZipEntry e = in.getNextEntry();
          if (e == null) break;
          if (!e.isDirectory()) {
            String name = e.getName();
            long size = e.getSize();

            if (size > Integer.MAX_VALUE)
              throw new IOException(name + " is too big at " + size + " bytes");
            ByteArrayOutputStream out;
            if (size <= 0) out = new ByteArrayOutputStream();
            else out = new ByteArrayOutputStream((int) size);
            GZIPOutputStream gOut = new GZIPOutputStream(out);
            IO.copy(in, gOut);
            gOut.close();
            byte data[] = out.toByteArray();
            contents.put(name, data);
            lastModified.put(name, e.getTime());
          }
          in.closeEntry();
        }
      } finally {
        Util.closeSilently(in);
      }
    }
示例#2
0
  static {
    Class<Version> c = Version.class;
    URL u = c.getResource(c.getSimpleName() + ".class");
    boolean fromFile = "file".equals(u.getProtocol());
    InputStream in = null;
    String release = null;
    String date = null;
    String plugin_release_date = null;
    if (!fromFile) {
      try {
        Properties versionProperties = new Properties();
        in = Version.class.getResourceAsStream("version.properties");
        if (in != null) {
          versionProperties.load(in);
          release = (String) versionProperties.get("release.number");
          date = (String) versionProperties.get("release.date");
          plugin_release_date = (String) versionProperties.get("plugin.release.date");
        }
      } catch (Exception e) {
        assert true; // ignore
      } finally {
        Util.closeSilently(in);
      }
    }
    if (release == null) {
      release = COMPUTED_RELEASE;
    }
    if (date == null) {
      date = COMPUTED_DATE;
    }
    if (plugin_release_date == null) {
      plugin_release_date = COMPUTED_PLUGIN_RELEASE_DATE;
    }

    RELEASE = release;
    DATE = date;
    CORE_PLUGIN_RELEASE_DATE = plugin_release_date;
    Date parsedDate;
    try {
      SimpleDateFormat fmt =
          new SimpleDateFormat(UpdateChecker.PLUGIN_RELEASE_DATE_FMT, Locale.ENGLISH);

      parsedDate = fmt.parse(CORE_PLUGIN_RELEASE_DATE);
    } catch (ParseException e) {
      if (SystemProperties.ASSERTIONS_ENABLED) {
        e.printStackTrace();
      }
      parsedDate = null;
    }
    releaseDate = parsedDate;
  }
  private boolean checkAuthorized(URL response) throws IOException {
    HttpURLConnection connection = (HttpURLConnection) response.openConnection();

    int responseCode = connection.getResponseCode();
    if (responseCode == 200) {
      BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String status = in.readLine();
      sessionId = Long.parseLong(in.readLine());
      username = in.readLine();
      Util.closeSilently(in);
      if ("OK".equals(status)) {
        LOGGER.info("Authorized session " + sessionId);
        return true;
      }
    }
    connection.disconnect();
    return false;
  }