Exemplo n.º 1
0
  /**
   * Sort all the EntryValue(s) from an Entry list into an array of EntryValue(s).
   *
   * @param <T> a generic type for EntryValue.
   * @param entryList an Entry list from whose EntryValue(s) will be sorted.
   * @return an array of EntryValue(s) of generic type <T>. Returns null if the entryList is null or
   *     it does not contain any values
   * @throws NullPointerException if the first Entry in the list is null.
   */
  public static <T extends EntryValue> T[] sortEntriesToValues(List<Entry<T>> entryList) {
    int len = 0;
    T[] valArray = null;

    if (entryList == null) {
      return valArray;
    }

    for (Entry<T> e : entryList) {
      len += e.size();
    }

    if (len == 0) {
      return valArray;
    }

    // Create valArray
    valArray = entryList.get(0).getValueFactory().newValueArray(len);

    // Add values from entries to valArray
    int i = 0;
    for (Entry<T> e : entryList) {
      for (T val : e.getValueList()) {
        valArray[i++] = val;
      }
    }

    // Sort values in valArray
    Arrays.sort(valArray);
    return valArray;
  }
 public int size(final String field) {
   ArgumentChecker.notNull(field, "field");
   final Entry e = _data.get(field);
   if (e == null) {
     return 0;
   }
   return e.size();
 }
Exemplo n.º 3
0
 /**
  * @deprecated in API 16 Adds an index set data type to the builder object
  * @param e element describing the index set data layout
  * @param size number of elements in the buffer
  * @param p primitive type
  * @return this
  */
 public Builder addIndexSetType(Element e, int size, Primitive p) {
   Entry indexType = new Entry();
   indexType.t = null;
   indexType.e = e;
   indexType.size = size;
   indexType.prim = p;
   mIndexTypes.addElement(indexType);
   return this;
 }
Exemplo n.º 4
0
 /**
  * @deprecated in API 16 Adds an index set data type to the builder object
  * @param t type of the index set data, could be null
  * @param p primitive type
  * @return this
  */
 public Builder addIndexSetType(Type t, Primitive p) {
   Entry indexType = new Entry();
   indexType.t = t;
   indexType.e = null;
   indexType.size = 0;
   indexType.prim = p;
   mIndexTypes.addElement(indexType);
   return this;
 }
Exemplo n.º 5
0
    private void initEntries() {
      if (entriesInited) {
        return;
      }

      if (!zipFileIndex.readFromIndex) {
        int from =
            -Arrays.binarySearch(zipFileIndex.entries, new Entry(dirName, ZipFileIndex.MIN_CHAR))
                - 1;
        int to = -Arrays.binarySearch(zipFileIndex.entries, new Entry(dirName, MAX_CHAR)) - 1;

        for (int i = from; i < to; i++) {
          entries.add(zipFileIndex.entries[i]);
        }
      } else {
        File indexFile = zipFileIndex.getIndexFile();
        if (indexFile != null) {
          RandomAccessFile raf = null;
          try {
            raf = new RandomAccessFile(indexFile, "r");
            raf.seek(writtenOffsetOffset);

            for (int nFiles = 0; nFiles < numEntries; nFiles++) {
              // Read the name bytes
              int zfieNameBytesLen = raf.readInt();
              byte[] zfieNameBytes = new byte[zfieNameBytesLen];
              raf.read(zfieNameBytes);
              String eName = new String(zfieNameBytes, "UTF-8");

              // Read isDir
              boolean eIsDir = raf.readByte() == (byte) 0 ? false : true;

              // Read offset of bytes in the real Jar/Zip file
              int eOffset = raf.readInt();

              // Read size of the file in the real Jar/Zip file
              int eSize = raf.readInt();

              // Read compressed size of the file in the real Jar/Zip file
              int eCsize = raf.readInt();

              // Read java time stamp of the file in the real Jar/Zip file
              long eJavaTimestamp = raf.readLong();

              Entry rfie = new Entry(dirName, eName);
              rfie.isDir = eIsDir;
              rfie.offset = eOffset;
              rfie.size = eSize;
              rfie.compressedSize = eCsize;
              rfie.javatime = eJavaTimestamp;
              entries.add(rfie);
            }
          } catch (Throwable t) {
            // Do nothing
          } finally {
            try {
              if (raf != null) {
                raf.close();
              }
            } catch (Throwable t) {
              // Do nothing
            }
          }
        }
      }

      entriesInited = true;
    }
Exemplo n.º 6
0
    private int readEntry(
        int pos, List<Entry> entryList, Map<RelativeDirectory, DirectoryEntry> directories)
        throws IOException {
      if (get4ByteLittleEndian(zipDir, pos) != 0x02014b50) {
        throw new ZipException("cannot read zip file entry");
      }

      int dirStart = pos + 46;
      int fileStart = dirStart;
      int fileEnd = fileStart + get2ByteLittleEndian(zipDir, pos + 28);

      if (zipFileIndex.symbolFilePrefixLength != 0
          && ((fileEnd - fileStart) >= symbolFilePrefixLength)) {
        dirStart += zipFileIndex.symbolFilePrefixLength;
        fileStart += zipFileIndex.symbolFilePrefixLength;
      }
      // Force any '\' to '/'. Keep the position of the last separator.
      for (int index = fileStart; index < fileEnd; index++) {
        byte nextByte = zipDir[index];
        if (nextByte == (byte) '\\') {
          zipDir[index] = (byte) '/';
          fileStart = index + 1;
        } else if (nextByte == (byte) '/') {
          fileStart = index + 1;
        }
      }

      RelativeDirectory directory = null;
      if (fileStart == dirStart) directory = getRelativeDirectory("");
      else if (lastDir != null && lastLen == fileStart - dirStart - 1) {
        int index = lastLen - 1;
        while (zipDir[lastStart + index] == zipDir[dirStart + index]) {
          if (index == 0) {
            directory = lastDir;
            break;
          }
          index--;
        }
      }

      // Sub directories
      if (directory == null) {
        lastStart = dirStart;
        lastLen = fileStart - dirStart - 1;

        directory = getRelativeDirectory(new String(zipDir, dirStart, lastLen, "UTF-8"));
        lastDir = directory;

        // Enter also all the parent directories
        RelativeDirectory tempDirectory = directory;

        while (directories.get(tempDirectory) == null) {
          directories.put(tempDirectory, new DirectoryEntry(tempDirectory, zipFileIndex));
          if (tempDirectory.path.indexOf("/") == tempDirectory.path.length() - 1) break;
          else {
            // use shared RelativeDirectory objects for parent dirs
            tempDirectory = getRelativeDirectory(tempDirectory.dirname().getPath());
          }
        }
      } else {
        if (directories.get(directory) == null) {
          directories.put(directory, new DirectoryEntry(directory, zipFileIndex));
        }
      }

      // For each dir create also a file
      if (fileStart != fileEnd) {
        Entry entry =
            new Entry(directory, new String(zipDir, fileStart, fileEnd - fileStart, "UTF-8"));

        entry.setNativeTime(get4ByteLittleEndian(zipDir, pos + 12));
        entry.compressedSize = get4ByteLittleEndian(zipDir, pos + 20);
        entry.size = get4ByteLittleEndian(zipDir, pos + 24);
        entry.offset = get4ByteLittleEndian(zipDir, pos + 42);
        entryList.add(entry);
      }

      return pos
          + 46
          + get2ByteLittleEndian(zipDir, pos + 28)
          + get2ByteLittleEndian(zipDir, pos + 30)
          + get2ByteLittleEndian(zipDir, pos + 32);
    }
Exemplo n.º 7
0
 /**
  * Returns the number of tasks currently in the timer
  *
  * @return The number of tasks currently in the timer
  */
 public int size() {
   int retval = 0;
   Collection<Entry> values = tasks.values();
   for (Entry entry : values) retval += entry.size();
   return retval;
 }