Ejemplo n.º 1
0
  private void updateLocalVersions() {
    if (NavigineApp.Navigation == null) return;

    for (int i = 0; i < mInfoList.size(); ++i) {
      LocationInfo info = mInfoList.get(i);
      String versionStr = LocationLoader.getLocalVersion(NavigineApp.AppContext, info.title);
      if (versionStr != null) {
        // Log.d(TAG, info.title + ": " + versionStr);
        info.localModified = versionStr.endsWith("+");
        if (info.localModified) versionStr = versionStr.substring(0, versionStr.length() - 1);
        try {
          info.localVersion = Integer.parseInt(versionStr);
        } catch (Throwable e) {
        }
      } else {
        info.localVersion = -1;

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }
      }
    }
    mAdapter.updateList();
  }
Ejemplo n.º 2
0
  private void putList(String name, List l) {
    _put(ARRAY, name);
    final int sizePos = _buf.position();
    _buf.putInt(0);

    for (int i = 0; i < l.size(); i++) _putObjectField(String.valueOf(i), l.get(i));

    _buf.put(EOO);
    _buf.putInt(sizePos, _buf.position() - sizePos);
  }
  /**
   * @param idx Index.
   * @return Conflict version.
   */
  @Nullable
  public GridCacheVersion conflictVersion(int idx) {
    if (conflictVers != null) {
      assert idx >= 0 && idx < conflictVers.size();

      return conflictVers.get(idx);
    }

    return null;
  }
Ejemplo n.º 4
0
  /** Prints the properties of the class for debugging purpose. */
  @Override
  public String toString() {
    String result = "";
    result += "recurFrequency: " + String.format("%#02x", this.recurFrequency) + "\n";
    result += "patternType: " + String.format("%#02x", this.patternType.getValue()) + "\n";
    result += "calendarType: " + String.format("%#02x", this.calendarType) + "\n";
    result += "endType: " + String.format("%#04x", this.endType) + "\n";

    result += "period: " + this.period + "\n";
    result += "occurenceCount: " + String.format("%#04x", this.occurenceCount) + "\n";
    result += "patternSpecific1: " + String.format("%#04x", this.patternSpecific1) + "\n";
    result += "patternSpecific2: " + String.format("%#04x", this.patternSpecific2) + "\n";
    result += "startDate hex: " + String.format("%#04x", this.startDate) + "\n";
    result += "endDate hex: " + String.format("%#04x", this.endDate) + "\n";

    result +=
        "startDate: "
            + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(windowsTimeToDateObject(this.startDate))
            + "\n";
    result +=
        "endDate: "
            + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(windowsTimeToDateObject(this.endDate))
            + "\n";

    for (int i = 0; i < modifiedInstanceCount; i++) {
      result +=
          "modified Instance date hex: " + String.format("%#04x", this.modifiedInstances[i]) + "\n";

      result +=
          "modified Instance date: "
              + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z")
                  .format(windowsTimeToDateObject(this.modifiedInstances[i]))
              + "\n";
    }

    for (int i = 0; i < deletedInstanceCount; i++) {
      result +=
          "deleted Instance date: "
              + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(deletedInstances.get(i))
              + "\n";
    }
    result += "patternSpecific2: " + String.format("%#04x", this.patternSpecific2) + "\n";

    result += "\n\n =====================Exeptions====================\n\n";

    for (ExceptionInfo info : exceptionInfo) {
      result += info.toString() + "\n\n";
    }
    return result;
  }
  static void testMixed(Charset cs) throws Throwable {
    CharsetDecoder dec =
        cs.newDecoder()
            .onMalformedInput(CodingErrorAction.REPLACE)
            .onUnmappableCharacter(CodingErrorAction.REPLACE);
    CharsetEncoder enc =
        cs.newEncoder()
            .onMalformedInput(CodingErrorAction.REPLACE)
            .onUnmappableCharacter(CodingErrorAction.REPLACE);
    List<Integer> cps = new ArrayList<>(0x10000);
    int off = 0;
    int cp = 0;
    while (cp < 0x10000) {
      if (enc.canEncode((char) cp)) {
        cps.add(cp);
      }
      cp++;
    }
    Collections.shuffle(cps);
    char[] bmpCA = new char[cps.size()];
    for (int i = 0; i < cps.size(); i++) bmpCA[i] = (char) (int) cps.get(i);
    String bmpStr = new String(bmpCA);
    // getBytes(csn);
    byte[] bmpBA = bmpStr.getBytes(cs.name());
    ByteBuffer bf = enc.reset().encode(CharBuffer.wrap(bmpCA));
    byte[] baNIO = new byte[bf.limit()];
    bf.get(baNIO, 0, baNIO.length);
    if (!Arrays.equals(bmpBA, baNIO)) {
      throw new RuntimeException("getBytes(csn) failed  -> " + cs.name());
    }

    // getBytes(cs);
    bmpBA = bmpStr.getBytes(cs);
    if (!Arrays.equals(bmpBA, baNIO))
      throw new RuntimeException("getBytes(cs) failed  -> " + cs.name());

    // new String(csn);
    String strSC = new String(bmpBA, cs.name());
    String strNIO = dec.reset().decode(ByteBuffer.wrap(bmpBA)).toString();
    if (!strNIO.equals(strSC)) {
      throw new RuntimeException("new String(csn) failed  -> " + cs.name());
    }

    // new String(cs);
    strSC = new String(bmpBA, cs);
    if (!strNIO.equals(strSC)) throw new RuntimeException("new String(cs) failed  -> " + cs.name());
  }
Ejemplo n.º 6
0
  private void startUpload(int index) {
    if (NavigineApp.Navigation == null) return;

    String userHash = NavigineApp.Settings.getString("user_hash", "");
    if (userHash.length() == 0) return;

    LocationInfo info = mInfoList.get(index);
    String location = new String(info.title);
    Log.d(TAG, String.format(Locale.ENGLISH, "Start upload: %s", location));

    synchronized (mLoaderMap) {
      if (!mLoaderMap.containsKey(location)) {
        LoaderState loader = new LoaderState();
        loader.location = location;
        loader.type = UPLOAD;
        loader.id = LocationLoader.startLocationUploader(location, info.archiveFile, true);
        mLoaderMap.put(location, loader);
      }
    }
    mAdapter.updateList();
  }
Ejemplo n.º 7
0
  public String postFile(URLFetchService us, List<PostObj> postobjlist) throws Exception {
    int index;

    Gson gson;
    String linkID;
    List<String> linkList;
    HTTPRequest req;
    String param;

    gson = new Gson();

    linkID = createUID();
    linkList = new ArrayList<String>();
    for (index = 0; index < postobjlist.size(); index++) {
      linkList.add(postobjlist.get(index).filelink);
    }

    param =
        URLEncoder.encode("postlist", "UTF-8")
            + "="
            + URLEncoder.encode(gson.toJson(postobjlist), "UTF-8")
            + '&'
            + URLEncoder.encode("linkid", "UTF-8")
            + "="
            + URLEncoder.encode(linkID, "UTF-8")
            + '&'
            + URLEncoder.encode("linklist", "UTF-8")
            + "="
            + URLEncoder.encode(gson.toJson(linkList), "UTF-8");
    req =
        new HTTPRequest(
            new URL("http://tnfshmoe.appspot.com/postdf89ksfxsyx9sfdex09usdjksd"), HTTPMethod.POST);
    req.setPayload(param.getBytes());
    us.fetch(req);

    return linkID;
  }
Ejemplo n.º 8
0
  private void selectItem(int index) {
    _info = mInfoList.get(index);
    if (!(new File(_info.archiveFile)).exists()) {
      String text =
          String.format(
              Locale.ENGLISH,
              "Location '%s' cannot be selected!\n" + "Please, download location first!",
              _info.title);
      Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
      return;
    }

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
    alertBuilder.setTitle(String.format(Locale.ENGLISH, "Location '%s'", _info.title));

    alertBuilder.setNegativeButton(
        "Delete location",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {
            deleteLocation(_info);
          }
        });
    alertBuilder.setPositiveButton(
        "Select location",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {
            selectLocation(_info);
          }
        });

    AlertDialog dialog = alertBuilder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
  }
Ejemplo n.º 9
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    int index;

    DatastoreService ds;
    MemcacheService ms;
    BlobstoreService bs;
    URLFetchService us;
    FileService fs;

    Map<String, List<BlobKey>> blobMap;
    BlobKey blobKey;
    BlobInfoFactory blobInfoFactory;
    BlobInfo blobInfo;

    int postCount;
    int postIndex;
    String postType;
    String postText;
    String postDelpw;
    String postShowgallery;
    DataObj dataObj;
    String filelink;

    String picUrl;
    HTTPResponse picRes;
    List<HTTPHeader> headerList;
    String picMime;
    String[] fileNamePart;
    AppEngineFile picFile;
    FileWriteChannel writeChannel;

    PostObj postObj;
    List<PostObj> postObjList;
    String linkID;

    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("text/plain");

    try {
      ds = DatastoreServiceFactory.getDatastoreService();
      ms = MemcacheServiceFactory.getMemcacheService();
      bs = BlobstoreServiceFactory.getBlobstoreService();
      us = URLFetchServiceFactory.getURLFetchService();
      fs = FileServiceFactory.getFileService();
      blobInfoFactory = new BlobInfoFactory(ds);

      blobMap = bs.getUploads(req);
      postCount = Integer.valueOf(req.getParameter("input_post_count"));
      postObjList = new ArrayList<PostObj>();

      for (postIndex = 0; postIndex < postCount; postIndex++) {
        try {
          postType = req.getParameter("input_post_type_" + postIndex);
          if (postType == null) {
            continue;
          }

          postText = req.getParameter("input_post_text_" + postIndex);
          postDelpw = req.getParameter("input_post_delpw_" + postIndex);
          postShowgallery = req.getParameter("input_post_showgallery_" + postIndex);
          if (postShowgallery == null) {
            postShowgallery = "";
          }

          if (postType.equals("file") == true) {
            blobKey = blobMap.get("input_post_file_" + postIndex).get(0);
            if (blobKey == null) {
              throw new Exception();
            }

            dataObj = new DataObj();
            dataObj.fileid = createUID();
            dataObj.posttime = new Date().getTime();
            dataObj.delpw = postDelpw;
            dataObj.blobkey = blobKey;
            dataObj.putDB(ds);

            blobInfo = blobInfoFactory.loadBlobInfo(dataObj.blobkey);
            filelink =
                "http://"
                    + req.getServerName()
                    + "/down/"
                    + dataObj.fileid
                    + "/"
                    + blobInfo.getFilename();
            postObj =
                new PostObj(
                    dataObj.fileid,
                    filelink,
                    blobInfo.getSize(),
                    dataObj.posttime,
                    dataObj.delpw,
                    postShowgallery);
            postObjList.add(postObj);
          } else if (postType.equals("url") == true) {
            picUrl = postText;

            picRes = us.fetch(new URL(picUrl));
            headerList = picRes.getHeaders();
            picMime = "application/octet-stream";
            for (index = 0; index < headerList.size(); index++) {
              if (headerList.get(index).getName().compareToIgnoreCase("Content-Type") == 0) {
                picMime = headerList.get(index).getValue();
                break;
              }
            }

            fileNamePart = picUrl.split("/");

            picFile = fs.createNewBlobFile(picMime, fileNamePart[fileNamePart.length - 1]);
            writeChannel = fs.openWriteChannel(picFile, true);
            writeChannel.write(ByteBuffer.wrap(picRes.getContent()));
            writeChannel.closeFinally();

            dataObj = new DataObj();
            dataObj.fileid = createUID();
            dataObj.posttime = new Date().getTime();
            dataObj.delpw = postDelpw;
            dataObj.blobkey = fs.getBlobKey(picFile);
            dataObj.putDB(ds);

            blobInfo = blobInfoFactory.loadBlobInfo(dataObj.blobkey);
            filelink =
                "http://"
                    + req.getServerName()
                    + "/down/"
                    + dataObj.fileid
                    + "/"
                    + blobInfo.getFilename();
            postObj =
                new PostObj(
                    dataObj.fileid,
                    filelink,
                    blobInfo.getSize(),
                    dataObj.posttime,
                    dataObj.delpw,
                    postShowgallery);
            postObjList.add(postObj);
          }
        } catch (Exception e) {
        }
      }

      linkID = postFile(us, postObjList);

      if (req.getParameter("specflag") != null) {
        resp.getWriter().print("http://tnfshmoe.appspot.com/link.jsp?linkid=" + linkID);
      } else {
        resp.sendRedirect("http://tnfshmoe.appspot.com/link.jsp?linkid=" + linkID);
      }
    } catch (Exception e) {
    }
  }
Ejemplo n.º 10
0
  /**
   * Calculates and creates the next calendar item.
   *
   * @param previousStartDate the start date of the previous occurrence.
   * @param previousEndDate the end date of the previous occurrence.
   * @return the new calendar item or null if there are no more calendar items from that recurrent
   *     series.
   */
  public CalendarItemTimerTask next(Date previousStartDate, Date previousEndDate) {
    if (dateOutOfRange(new Date())) {
      return null;
    }
    Date startDate = previousStartDate;
    Date endDate = null;
    boolean executeNow = false;
    long duration = sourceTask.getEndDate().getTime() - sourceTask.getStartDate().getTime();
    switch (patternType) {
      case Day:
        {
          startDate = new Date(startDate.getTime() + period * 60000);
          endDate = new Date(previousEndDate.getTime() + period * 60000);
          Date currentDate = new Date();
          if (endDate.before(currentDate)) {
            long offset = currentDate.getTime() - endDate.getTime();
            offset -= offset % (period * 60000);
            if (endDate.getTime() + offset < currentDate.getTime()) {
              offset += period * 60000;
            }

            startDate = new Date(startDate.getTime() + offset);
          }

          Calendar cal = Calendar.getInstance();
          cal.setTime(startDate);
          Calendar cal2 = (Calendar) cal.clone();
          cal.set(Calendar.HOUR_OF_DAY, 0);
          cal.set(Calendar.MINUTE, 0);
          cal.set(Calendar.SECOND, 0);
          cal.set(Calendar.MILLISECOND, 0);
          while (deletedInstances.contains(cal.getTime())) {
            cal.add(Calendar.MINUTE, period);
            cal2.add(Calendar.MINUTE, period);
          }

          if (dateOutOfRange(cal.getTime())) {
            return null;
          }
          startDate = cal2.getTime();
          endDate = new Date(startDate.getTime() + duration);
          if (startDate.before(currentDate)) {
            executeNow = true;
          }

          return new CalendarItemTimerTask(
              sourceTask.getStatus(), startDate, endDate, sourceTask.getId(), executeNow, this);
        }
      case Week:
        {
          Calendar cal = Calendar.getInstance();
          /** The enum for the firstDow field is the same as Calendar day of week enum + 1 day */
          cal.setFirstDayOfWeek(firstDow + 1);
          cal.setTime(startDate);
          int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
          int index = allowedDaysOfWeek.indexOf(dayOfWeek);
          if (++index < allowedDaysOfWeek.size()) {
            cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(index));
            startDate = cal.getTime();
            endDate = new Date(startDate.getTime() + duration);
          } else {
            cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(0));
            cal.add(Calendar.WEEK_OF_YEAR, period);
            startDate = cal.getTime();
            endDate = new Date(startDate.getTime() + duration);
          }
          Date currentDate = new Date();
          if (endDate.before(currentDate)) {
            cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(0));
            endDate = new Date(cal.getTimeInMillis() + duration);
            long offset = (currentDate.getTime() - endDate.getTime());

            // 1 week = 604800000 is milliseconds
            offset -= offset % (period * 604800000);
            if (endDate.getTime() + offset < currentDate.getTime()) {
              cal.add(Calendar.WEEK_OF_YEAR, (int) (offset / (period * 604800000)));
              int i = 1;
              while (((cal.getTimeInMillis() + duration) < (currentDate.getTime()))) {
                if (i == allowedDaysOfWeek.size()) {
                  cal.add(Calendar.WEEK_OF_YEAR, period);
                  i = 0;
                }
                cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(i));
                i++;
              }

              startDate = cal.getTime();
            } else {
              startDate = new Date(cal.getTimeInMillis() + offset);
            }
          }

          cal.setTime(startDate);
          Calendar cal2 = (Calendar) cal.clone();
          cal.set(Calendar.HOUR_OF_DAY, 0);
          cal.set(Calendar.MINUTE, 0);
          cal.set(Calendar.SECOND, 0);
          cal.set(Calendar.MILLISECOND, 0);
          dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
          index = allowedDaysOfWeek.indexOf(dayOfWeek) + 1;
          while (deletedInstances.contains(cal.getTime())) {
            if (index >= allowedDaysOfWeek.size()) {
              index = 0;
              cal.add(Calendar.WEEK_OF_YEAR, period);
              cal2.add(Calendar.WEEK_OF_YEAR, period);
            }
            cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(index));
            cal2.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(index));
            index++;
          }
          startDate = cal2.getTime();
          endDate = new Date(startDate.getTime() + duration);
          if (dateOutOfRange(endDate)) return null;
          if (startDate.before(currentDate)) {
            executeNow = true;
          }

          return new CalendarItemTimerTask(
              sourceTask.getStatus(), startDate, endDate, sourceTask.getId(), executeNow, this);
        }
      case Month:
      case MonthEnd:
      case HjMonth:
      case HjMonthEnd:
        {
          return nextMonth(startDate, endDate, false);
        }
      case MonthNth:
      case HjMonthNth:
        {
          if (patternSpecific1 == 0x7f && patternSpecific2 == 0x05) {
            return nextMonth(startDate, endDate, true);
          }

          return nextMonthN(startDate, endDate);
        }
    }
    return null;
  }
Ejemplo n.º 11
0
  public static void main(String[] args) throws Throwable {
    final int itrs = Integer.getInteger("iterations", 100000);
    // final int itrs = Integer.getInteger("iterations", 12);
    final int size = Integer.getInteger("size", 2048);
    final int subsize = Integer.getInteger("subsize", 128);
    final int maxchar = Integer.getInteger("maxchar", 128);
    final String regex = System.getProperty("filter");
    final Pattern filter = (regex == null) ? null : Pattern.compile(regex);
    final boolean useSecurityManager = Boolean.getBoolean("SecurityManager");
    if (useSecurityManager) System.setSecurityManager(new PermissiveSecurityManger());
    final Random rnd = new Random();

    String[] csns =
        new String[] {
          "Big5",
          "Johab",
          "EUC_CN",
          "EUC_KR",
          "MS932",
          "MS936",
          "MS949",
          "MS950",
          "GBK",
          "Big5_HKSCS",
          "Big5_HKSCS_2001",
          "Big5_Solaris",
          "MS950_HKSCS",
          "MS950_HKSCS_XP",
          "IBM1364",
          "IBM1381",
          "IBM1383",
          "IBM930",
          "IBM933",
          "IBM935",
          "IBM937",
          "IBM939",
          "IBM942",
          "IBM943",
          "IBM948",
          "IBM949",
          "IBM950",
          "IBM970",
        };

    ArrayList<long[]> sum = new ArrayList<>();

    for (final String csn : csns) {
      final Charset cs = Charset.forName(csn);
      List<Integer> cps = new ArrayList<>(0x4000);
      int off = 0;
      int cp = 0;
      int n = 0;
      CharsetEncoder enc = cs.newEncoder();
      while (cp < 0x10000 && n < cps.size()) {
        if (enc.canEncode((char) cp)) {
          cps.add(cp);
          n++;
        }
        cp++;
      }
      Collections.shuffle(cps);
      char[] ca = new char[cps.size()];
      for (int i = 0; i < cps.size(); i++) ca[i] = (char) (int) cps.get(i);

      System.out.printf("%n--------%s---------%n", csn);
      for (int sz = 8; sz <= 2048; sz *= 2) {
        System.out.printf("   [len=%d]%n", sz);

        final char[] chars = Arrays.copyOf(ca, sz);
        final String str = new String(chars);
        final byte[] bs = str.getBytes(cs);

        Job[] jobs = {
          new Job("String decode: csn") {
            public void work() throws Throwable {
              for (int i = 0; i < itrs; i++) new String(bs, csn);
            }
          },
          new Job("String decode: cs") {
            public void work() throws Throwable {
              for (int i = 0; i < itrs; i++) new String(bs, cs);
            }
          },
          new Job("String encode: csn") {
            public void work() throws Throwable {
              for (int i = 0; i < itrs; i++) str.getBytes(csn);
            }
          },
          new Job("String encode: cs") {
            public void work() throws Throwable {
              for (int i = 0; i < itrs; i++) str.getBytes(cs);
            }
          },
        };
        sum.add(time(jobs));
      }
    }
  }
  /**
   * @param idx Index to get.
   * @return Write value - either value, or transform closure.
   */
  public CacheObject writeValue(int idx) {
    if (vals != null) return vals.get(idx);

    return null;
  }
  /**
   * @param idx Key index.
   * @return Value.
   */
  @SuppressWarnings("unchecked")
  public CacheObject value(int idx) {
    assert op == UPDATE : op;

    return vals.get(idx);
  }
Ejemplo n.º 14
0
 private static ServerAddress _checkAddress(List<ServerAddress> addrs) {
   if (addrs == null) throw new NullPointerException("addresses can't be null");
   if (addrs.size() == 0) throw new IllegalArgumentException("need to specify at least 1 address");
   return addrs.get(0);
 }