Tries to get best value split(number of elements in each value file) which can be expressed as power of 2.

@return Returns the size of value file splits as power of 2.

@throws IOException
170976
private int bagSizePower() throws IOException
  {
    long avgObjectSize = (valuesOut.size() + numWritten - 1) / numWritten;

    for (int i = 31; i >= 0; --i) {
      if ((1L << i) * avgObjectSize <= fileSizeLimit) {
        if (actuallyFits(i)) {
          return i;
        }
      }
    }
    throw new ISE(
        "no value split found with fileSizeLimit [%d], avgObjectSize [%d]",
        fileSizeLimit,
        avgObjectSize
    );
  }
1372014
public int maxValue()
    {
        final int missingValue = this.missingValue;
        int max = size == 0 ? missingValue : Integer.MIN_VALUE;

        final int[] entries = this.entries;
        @DoNotSub final int length = entries.length;

        for (@DoNotSub int valueIndex = 1; valueIndex < length; valueIndex += 2)
        {
            final int value = entries[valueIndex];
            if (value != missingValue)
            {
                max = Math.max(max, value);
            }
        }

        return max;
    }
973329
public static <T extends Value> List<List<T>> split(List<T> input, long targetSize) {
        Collections.sort(input, new Comparator<Value>() {
            public int compare(Value o1, Value o2) {
                return new Long(o1.getValue()).compareTo(new Long(o2.getValue()));
            }
        });
        List<T> smaller = new ArrayList<T>();
        List<T> bigger = new ArrayList<T>();
        for(T v: input) {
            if(v.getValue() >= targetSize) {
                bigger.add(v);
            } else {
                smaller.add(v);
            }
        }
        List<List<T>> ret = new ArrayList<List<T>>();
        for(T b: bigger) {
            List<T> elem = new ArrayList<T>();
            elem.add(b);
            ret.add(elem);
        }

        while(smaller.size()>0) {
            ret.add(removeBestSubset(smaller, targetSize));
        }
        return ret;
    }
193161
public static List<File> split(File inputFile, File outputDirectory) throws IOException {
        ImageInputStream input = null;
        List<File> outputFiles = new ArrayList<>();
        try {
            input = ImageIO.createImageInputStream(inputFile);
            List<TIFFPage> pages = getPages(input);
            int pageNo = 1;
            for (TIFFPage tiffPage : pages) {
                ArrayList<TIFFPage> outputPages = new ArrayList<TIFFPage>(1);
                ImageOutputStream outputStream = null;
                try {
                    File outputFile = new File(outputDirectory, String.format("%04d", pageNo) + ".tif");
                    outputStream = ImageIO.createImageOutputStream(outputFile);
                    outputPages.clear();
                    outputPages.add(tiffPage);
                    writePages(outputStream, outputPages);
                    outputFiles.add(outputFile);
                }
                finally {
                    if (outputStream != null) {
                        outputStream.flush();
                        outputStream.close();
                    }
                }
                ++pageNo;
            }
        }
        finally {
            if (input != null) {
                input.close();
            }
        }
        return outputFiles;
    }
739293
private long getChunkSize() throws IOException {
        final int st = this.state;
        switch (st) {
        case CHUNK_CRLF:
            this.buffer.clear();
            final int bytesRead1 = this.in.readLine(this.buffer);
            if (bytesRead1 == -1) {
                throw new MalformedChunkCodingException(
                    "CRLF expected at end of chunk");
            }
            if (!this.buffer.isEmpty()) {
                throw new MalformedChunkCodingException(
                    "Unexpected content at the end of chunk");
            }
            state = CHUNK_LEN;
            //$FALL-THROUGH$
        case CHUNK_LEN:
            this.buffer.clear();
            final int bytesRead2 = this.in.readLine(this.buffer);
            if (bytesRead2 == -1) {
                throw new ConnectionClosedException("Premature end of chunk coded message body: " +
                        "closing chunk expected");
            }
            int separator = this.buffer.indexOf(';');
            if (separator < 0) {
                separator = this.buffer.length();
            }
            final String s = this.buffer.substringTrimmed(0, separator);
            try {
                return Long.parseLong(s, 16);
            } catch (final NumberFormatException e) {
                throw new MalformedChunkCodingException("Bad chunk header: " + s);
            }
        default:
            throw new IllegalStateException("Inconsistent codec state");
        }
    }
470960
public int read(int width) throws IOException {
        if (width == 0) {
            return 0;
        }
        if (width < 0 || width > 32) {
            throw new IOException("Bad read width.");
        }
        int result = 0;
        while (width > 0) {
            if (this.available == 0) {
                this.unread = this.in.read();
                if (this.unread < 0) {
                    throw new IOException("Attempt to read past end.");
                }
                this.available = 8;
            }
            int take = width;
            if (take > this.available) {
                take = this.available;
            }
            result |= ((this.unread >>> (this.available - take)) &
                    ((1 << take) - 1)) << (width - take);
            this.nrBits += take;
            this.available -= take;
            width -= take;
        }
        return result;
    }
1302938
@Override
    public int size() {
        stateLock.readLock().lock();
        try {
            switch (state) {
                default:
                    // This list might be empty or full or somewhere in between:
                    // we don't know until we look!
                    preFetchAll();
                    // The list is now either complete or timed out - recurse to find the result.
                    return size();
                case TIMED_OUT:
                    return currentSize();
                case COMPLETE_WITH_FAILURES:
                    return elements.length - failedKeys.size();
                case COMPLETE:
                    return elements.length;
            }
        } finally {
            stateLock.readLock().unlock();
        }
    }
224578
public static double parseFloat(InputStream inputStream, final int size) throws IOException {
        byte[] buffer = new byte[size];
        int numberOfReadsBytes = inputStream.read(buffer, 0, size);
        assert numberOfReadsBytes == size;

        ByteBuffer byteBuffer = ByteBuffer.wrap(buffer).order(ByteOrder.BIG_ENDIAN);
        if (8 == size) {
            return byteBuffer.getDouble();
        }

        return byteBuffer.getFloat();
    }
706442
public long getSize() {
        int idSize = dumpClass.getHprofBuffer().getIDSize();

        return dumpClass.classDumpSegment.getMinimumInstanceSize() + HPROF_ARRAY_OVERHEAD + ((long)idSize * getLength());
    }
723451
@Override
	public FileInputSplit[] createInputSplits(int minNumSplits) throws IOException {
		int numAvroFiles = 0;
		final Path path = this.filePath;
		// get all the files that are involved in the splits
		final FileSystem fs = path.getFileSystem();
		final FileStatus pathFile = fs.getFileStatus(path);

		if (!acceptFile(pathFile)) {
			throw new IOException("The given file does not pass the file-filter");
		}
		if (pathFile.isDir()) {
			// input is directory. list all contained files
			final FileStatus[] dir = fs.listStatus(path);
			for (int i = 0; i < dir.length; i++) {
				if (!dir[i].isDir() && acceptFile(dir[i])) {
					numAvroFiles++;
				}
			}
		} else {
			numAvroFiles = 1;
		}
		return super.createInputSplits(numAvroFiles);
	}
599471
@Override
    public long length()
                    throws IOException {
        int len = physical.size();
        int answer = 0;
        for (int i = 0; i < len; i++) {
            RandomAccessFile raf = (RandomAccessFile) physical.get(i);
            if (raf != null) {
                answer += raf.length();
            }
        }
        return answer;
    }
1364118
private long getTotalUploadSize() throws IOException {
        long size = 0;
        for (Map.Entry<String, File> entry : files.entrySet()) {
            size += entry.getValue().length();
        }

        for (Map.Entry<String, InputStream> entry : fileStreams.entrySet()) {
            size += entry.getValue().available();
        }
        return size;
    }
506749
public int getDataSize() {
        // Data size is given by lvs
        int size = 0;
        for(int i=0; i<numLVs; i++) {
            size += IOUtils.toInt(lvs[i]);
        }
        return size;
    }
415457
protected boolean splitSegments() {
		boolean change = false;

		work.reset();
		for( int i = 0; i < splits.size-1; i++ ) {
			int start = splits.data[i];
			int end = splits.data[i+1];

			int bestIndex = selectSplitBetween(start, end);
			if( bestIndex >= 0 ) {
				change |= true;
				work.add(start);
				work.add(bestIndex);
			} else {
				work.add(start);
			}
		}
		work.add(splits.data[ splits.size-1] );

		// swap the two lists
		GrowQueue_I32 tmp = work;
		work = splits;
		splits = tmp;

		return change;
	}
921344
public static long getSize(File file) {
        if (file.exists()) {
            if (!file.isFile()) {
                long size = 0;
                File[] files = file.listFiles();
                if (files != null && files.length > 0) {
                    for (File f : files) {
                        size += getSize(f);
                    }
                }
                return size;
            } else {
                return file.length();
            }
        }
        return 0;
    }
333579
int read() throws IOException {
        int nextInt = -1;
        if (!hasSplit) {
            split();
        }
        if (beforeDoctype != null) {
            nextInt = beforeDoctype.read();
            if (nextInt == -1) {
                beforeDoctype = null;
            }
        }
        if (nextInt == -1 && decl != null) {
            nextInt = decl.read();
            if (nextInt == -1) {
                decl = null;
            }
        }
        if (nextInt == -1 && afterDoctype != null) {
            nextInt = afterDoctype.read();
            if (nextInt == -1) {
                afterDoctype = null;
            }
        }
        if (nextInt == -1) {
            nextInt = original.read();
        }
        return nextInt;
    }
512343
private void split() throws IOException {
        hasSplit = true;
        IntegerBuffer before = new IntegerBuffer();
        IntegerBuffer after = new IntegerBuffer();

        int current;
        boolean ready = false;
        boolean stillNeedToSeeDoctype = true;
        while (!ready && (current = original.read()) != -1) {
            if (Character.isWhitespace((char) current)) {
                before.append(current);
            } else if (current == '<') {
                // could be XML declaration, comment, PI, DOCTYPE
                // or the first element
                int[] elementOrDeclOr = readUntilCloseCharIsReached();
                if (elementOrDeclOr.length > 0) {
                    if (elementOrDeclOr[0] == '?') {
                        // XML declaration or PI
                        before.append('<');
                        before.append(elementOrDeclOr);
                    } else if (elementOrDeclOr[0] != '!') {
                        // first element
                        after.append('<');
                        after.append(elementOrDeclOr);
                        stillNeedToSeeDoctype = false;
                        ready = true;
                    } else {
                        // comment or doctype
                        IntegerBuffer b =
                            new IntegerBuffer(elementOrDeclOr.length);
                        b.append(elementOrDeclOr);
                        if (b.indexOf(DOCTYPE_INTS) == -1) {
                            after.append('<');
                            after.append(elementOrDeclOr);
                        } else {
                            // swallow old declaration
                            stillNeedToSeeDoctype = false;
                        }
                        ready = true;
                    }
                } else {
                    after.append('<');
                    stillNeedToSeeDoctype = false;
                    ready = true;
                }
            } else {
                after.append(current);
                stillNeedToSeeDoctype = false;
                ready = true;
            }
        }

        // need to eliminate original DOCTYPE if it exists
        while (stillNeedToSeeDoctype && (current = original.read()) != -1) {
            if (Character.isWhitespace((char) current)) {
                after.append(current);
            } else if (current == '<') {
                int[] elementOrDeclOr = readUntilCloseCharIsReached();
                if (elementOrDeclOr.length > 0) {
                    if (elementOrDeclOr[0] == '?') {
                        // PI
                        after.append('<');
                        after.append(elementOrDeclOr);
                    } else if (elementOrDeclOr[0] != '!') {
                        // first element
                        after.append('<');
                        after.append(elementOrDeclOr);
                        stillNeedToSeeDoctype = false;
                    } else {
                        // comment or doctype
                        IntegerBuffer b =
                            new IntegerBuffer(elementOrDeclOr.length);
                        b.append(elementOrDeclOr);
                        if (b.indexOf(DOCTYPE_INTS) == -1) {
                            after.append('<');
                            after.append(elementOrDeclOr);
                        } else {
                            // swallow old declaration
                            stillNeedToSeeDoctype = false;
                        }
                    }
                } else {
                    after.append('<');
                    stillNeedToSeeDoctype = false;
                }
            } else {
                after.append(current);
                stillNeedToSeeDoctype = false;
            }
        }

        beforeDoctype = before.size() > 0
            ? new IntBufferReadable(before) : null;
        afterDoctype = after.size() > 0
            ? new IntBufferReadable(after) : null;
    }