下面列出了java.awt.image.PixelInterleavedSampleModel#com.google.common.primitives.Ints 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @see <a href="https://github.com/logstash-plugins/logstash-input-beats/blob/master/PROTOCOL.md#data-frame-type">'data' frame type</a>
*/
private Collection<ByteBuf> parseDataFrame(Channel channel, ByteBuf channelBuffer) throws IOException {
sequenceNum = channelBuffer.readUnsignedInt();
LOG.trace("Received sequence number {}", sequenceNum);
final int pairs = Ints.saturatedCast(channelBuffer.readUnsignedInt());
final JsonFactory jsonFactory = new JsonFactory();
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (final JsonGenerator jg = jsonFactory.createGenerator(outputStream)) {
jg.writeStartObject();
for (int i = 0; i < pairs; i++) {
final String key = parseDataItem(channelBuffer);
final String value = parseDataItem(channelBuffer);
jg.writeStringField(key, value);
}
jg.writeEndObject();
}
final ByteBuf buffer = Unpooled.wrappedBuffer(outputStream.toByteArray());
sendACK(channel);
return Collections.singleton(buffer);
}
private void init() {
int tentativePort = config.port;
Splitter splitter = Splitter.on(':').trimResults().omitEmptyStrings().limit(2);
StringBuilder sb = new StringBuilder();
for (String host : Splitter.on(',').trimResults().omitEmptyStrings().split(
config.hosts)) {
List<String> h = splitter.splitToList(host);
sb.append(h.get(0)).append(',');
if (h.size() > 1 && tentativePort <= 0) {
tentativePort = Ints.tryParse(h.get(1));
}
}
config.hosts = sb.deleteCharAt(sb.length() - 1).toString();
config.port = tentativePort;
// update timeouts
config.connectionTimeout = config.connectionTimeout * 1000;
config.readTimeout = config.readTimeout * 1000;
}
@Override
public Iterable<ObjectStoreDeleteOperation> convertRecord(Class<?> outputSchema, GenericRecord inputRecord,
WorkUnitState workUnit) throws DataConversionException {
Optional<Object> fieldValue = AvroUtils.getFieldValue(inputRecord, this.objectIdField);
byte[] objectId;
if (fieldValue.isPresent()) {
if (fieldValue.get() instanceof Utf8) {
objectId = ((Utf8) fieldValue.get()).getBytes();
} else if (fieldValue.get() instanceof String) {
objectId = ((String) fieldValue.get()).getBytes(Charsets.UTF_8);
} else if (fieldValue.get() instanceof Long) {
objectId = Longs.toByteArray((Long) fieldValue.get());
} else if (fieldValue.get() instanceof Integer) {
objectId = Ints.toByteArray((Integer) fieldValue.get());
} else {
objectId = (byte[]) fieldValue.get();
}
return new SingleRecordIterable<ObjectStoreDeleteOperation>(ObjectStoreOperationBuilder.deleteBuilder()
.withObjectId(objectId).build());
} else {
throw new DataConversionException(String.format("Object Id field %s not found in record %s", this.objectIdField,
inputRecord));
}
}
private static long normalizeIntegerValue(Type type, long value)
{
if (type.equals(BIGINT)) {
return value;
}
if (type.equals(INTEGER)) {
return Ints.saturatedCast(value);
}
if (type.equals(SMALLINT)) {
return Shorts.saturatedCast(value);
}
if (type.equals(TINYINT)) {
return SignedBytes.saturatedCast(value);
}
throw new IllegalArgumentException("Unexpected type: " + type);
}
/**
* Shows a popup menu for a given mouse event.
*
* @param event The event that triggered the popup menu.
*/
private void showPopupMenu(final MouseEvent event) {
final JTable traceTable = m_tracesPanel.getTracesTable();
final int mouseRow = traceTable.rowAtPoint(event.getPoint());
if (mouseRow != -1) {
final int[] rows = traceTable.getSelectedRows();
if (Ints.asList(rows).indexOf(mouseRow) != -1) {
traceTable.setRowSelectionInterval(mouseRow, mouseRow);
}
}
// Make sure at least one row is selected
final int minIndex =
m_tracesPanel.getTracesTable().getSelectionModel().getMinSelectionIndex();
if (minIndex != -1) {
final JPopupMenu popupMenu =
new CEventListTableMenu(
(JFrame) SwingUtilities.getWindowAncestor(CTracesNodeComponent.this),
m_tracesPanel.getTracesTable(), m_container.getTraceProvider());
popupMenu.show(m_tracesPanel.getTracesTable(), event.getX(), event.getY());
}
}
/**
* Validate the checksum of the notice against the domain label.
*/
public void validate(String domainLabel) throws InvalidChecksumException {
// According to http://tools.ietf.org/html/draft-lozano-tmch-func-spec-08#section-6.3, a TCNID
// is always 8 chars of checksum + 19 chars of a decimal notice id. Check the length before
// taking substrings to avoid an IndexOutOfBoundsException.
String tcnId = getNoticeId().getTcnId();
checkArgument(tcnId.length() == 27);
int checksum = Ints.fromByteArray(base16().decode(Ascii.toUpperCase(tcnId.substring(0, 8))));
String noticeId = tcnId.substring(8);
checkArgument(CharMatcher.inRange('0', '9').matchesAllOf(noticeId));
// The checksum in the first 8 chars must match the crc32 of label + expiration + notice id.
String stringToHash =
domainLabel + MILLISECONDS.toSeconds(getExpirationTime().getMillis()) + noticeId;
int computedChecksum = crc32().hashString(stringToHash, UTF_8).asInt();
if (checksum != computedChecksum) {
throw new InvalidChecksumException();
}
}
/**
* Compute the broadcast rules according to:
* https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html
*
* Note that the array can be null if the arrays are already equal
* in shape.
*
* This function should be used in conjunction with
* the shape ops.
*
* @param left the left array
* @param right the right array (the array to be broadcasted
* @return the broadcast dimensions if any
*/
public static int[] getBroadcastDimensions(int[] left,int[] right) {
if(Arrays.equals(left,right))
return null;
int n = Math.min(left.length,right.length);
List<Integer> dims = new ArrayList<>();
int leftIdx = left.length - 1;
int rightIdx = right.length - 1;
for(int i = n - 1; i >= 0; i--) {
if(left[leftIdx] != right[rightIdx] && right[rightIdx] == 1 || left[leftIdx] == 1) {
dims.add(i);
}
else if(left[leftIdx] != right[rightIdx]) {
throw new IllegalArgumentException("Unable to broadcast dimension " + i + " due to shape mismatch. Right shape must be 1. "
+ "Left array shape: " + Arrays.toString(left) + ", right array shape: " + Arrays.toString(right));
}
leftIdx--;
rightIdx--;
}
Collections.reverse(dims);
return Ints.toArray(dims);
}
/**
* Returns the string representation of an {@link InetAddress}.
*
* <p>For IPv4 addresses, this is identical to {@link InetAddress#getHostAddress()}, but for IPv6
* addresses, the output follows <a href="http://tools.ietf.org/html/rfc5952">RFC 5952</a> section
* 4. The main difference is that this method uses "::" for zero compression, while Java's version
* uses the uncompressed form.
*
* <p>This method uses hexadecimal for all IPv6 addresses, including IPv4-mapped IPv6 addresses
* such as "::c000:201". The output does not include a Scope ID.
*
* @param ip {@link InetAddress} to be converted to an address string
* @return {@code String} containing the text-formatted IP address
* @since 10.0
*/
public static String toAddrString(InetAddress ip) {
Preconditions.checkNotNull(ip);
if (ip instanceof Inet4Address) {
// For IPv4, Java's formatting is good enough.
return ip.getHostAddress();
}
Preconditions.checkArgument(ip instanceof Inet6Address);
byte[] bytes = ip.getAddress();
int[] hextets = new int[IPV6_PART_COUNT];
for (int i = 0; i < hextets.length; i++) {
hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
}
compressLongestRunOfZeroes(hextets);
return hextetsToIPv6String(hextets);
}
@Step
private void verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(final List<TargetUpdateStatus> unknown,
final List<Target> expected) {
final String query = "updatestatus==unknown and (name==*targ-A* or description==*targ-A*)";
assertThat(targetManagement
.findByFilters(PAGE, new FilterParams(unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0]))
.getContent()).as("has number of elements").hasSize(99)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countByFilters(unknown, null, "%targ-A%", null,
Boolean.FALSE, new String[0])))
.as("and contains the following elements").containsAll(expected)
.as("and filter query returns the same result")
.containsAll(targetManagement.findByRsql(PAGE, query).getContent());
}
public byte[] toBytes()
{
byte[] data = new byte[0];
//WRITE NAME SIZE
byte[] nameBytes = this.name.getBytes(StandardCharsets.UTF_8);
int nameLength = nameBytes.length;
byte[] nameLengthBytes = Ints.toByteArray(nameLength);
data = Bytes.concat(data, nameLengthBytes);
//WRITE NAME
data = Bytes.concat(data, nameBytes);
//WRITE VOTERS SIZE
int votersLength = this.voters.size();
byte[] votersLengthBytes = Ints.toByteArray(votersLength);
data = Bytes.concat(data, votersLengthBytes);
//WRITE VOTERS
for(Account voter: this.voters)
{
data = Bytes.concat(data, Base58.decode(voter.getAddress()));
}
return data;
}
/**
* Creates a {@link Skill} from a {@link CSVRecord}.
* @param record The record.
* @return The {@link Skill} or {@link Optional#empty()} if the record was invalid.
*/
public static Optional<Skill> fromCsv(CSVRecord record) {
if (record.size() < 3) {
return Optional.empty();
}
Integer rank = Ints.tryParse(record.get(0));
if (rank == null) {
return Optional.empty();
}
Integer level = Ints.tryParse(record.get(1));
if (level == null) {
return Optional.empty();
}
Long experience = Longs.tryParse(record.get(2));
if (experience == null) {
return Optional.empty();
}
return Optional.of(new Skill(rank, level, experience));
}
/**
* Returns the string representation of an {@link InetAddress}.
*
* <p>For IPv4 addresses, this is identical to {@link InetAddress#getHostAddress()}, but for IPv6
* addresses, the output follows <a href="http://tools.ietf.org/html/rfc5952">RFC 5952</a> section
* 4. The main difference is that this method uses "::" for zero compression, while Java's version
* uses the uncompressed form.
*
* <p>This method uses hexadecimal for all IPv6 addresses, including IPv4-mapped IPv6 addresses
* such as "::c000:201". The output does not include a Scope ID.
*
* @param ip {@link InetAddress} to be converted to an address string
* @return {@code String} containing the text-formatted IP address
* @since 10.0
*/
public static String toAddrString(InetAddress ip) {
Preconditions.checkNotNull(ip);
if (ip instanceof Inet4Address) {
// For IPv4, Java's formatting is good enough.
return ip.getHostAddress();
}
Preconditions.checkArgument(ip instanceof Inet6Address);
byte[] bytes = ip.getAddress();
int[] hextets = new int[IPV6_PART_COUNT];
for (int i = 0; i < hextets.length; i++) {
hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
}
compressLongestRunOfZeroes(hextets);
return hextetsToIPv6String(hextets);
}
/**
* Creates a {@link HiscoreActivity} from a {@link CSVRecord}.
* @param record The record.
* @return The {@link HiscoreActivity} or {@link Optional#empty()} if the record was invalid.
*/
public static Optional<HiscoreActivity> fromCsv(CSVRecord record) {
if (record.size() < 2) {
return Optional.empty();
}
Integer rank = Ints.tryParse(record.get(0));
if (rank == null) {
return Optional.empty();
}
Integer score = Ints.tryParse(record.get(1));
if (score == null) {
return Optional.empty();
}
return Optional.of(new HiscoreActivity(rank, score));
}
@Step
private void verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(final DistributionSet installedSet,
final List<TargetUpdateStatus> pending, final Target expected) {
final String query = "updatestatus==pending and installedds.name==" + installedSet.getName();
assertThat(targetManagement
.findByFilters(PAGE,
new FilterParams(pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0]))
.getContent())
.as("has number of elements").hasSize(1).as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, null,
installedSet.getId(), Boolean.FALSE, new String[0])))
.as("and contains the following elements").containsExactly(expected)
.as("and filter query returns the same result")
.containsAll(targetManagement.findByRsql(PAGE, query).getContent());
}
/**
* deletes all selected columns if it is not present in the <code>exp</code>
* List
*
* @param table the table to DELETE columns
* @param exp columns to avoid deleting
* @see #deletecol(javax.swing.JTable, int)
*/
static void deletecols(JTable table, int[] exp) {
Integer[] selcols;
try {
TableColumnModel tcm = table.getColumnModel();
selcols = ArrayUtils.toObject(table.getSelectedColumns());
Arrays.sort(selcols, Collections.reverseOrder());
List<Integer> explist = Ints.asList(exp);
for (int i : selcols) {
if (!explist.contains(i)) {
tcm.removeColumn(tcm.getColumn(i));
}
}
} catch (Exception e) {
Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, e);
}
}
@Override
public int compareTo(IntArray intArray) {
if(this.backingArray.length == 0 || intArray.backingArray.length == 0) {
return 1;
}
else if(Arrays.equals(backingArray,intArray.backingArray))
return 1;
return Ints.compare(Ints.max(backingArray),Ints.max(intArray.backingArray));
}
public static int roundToPowerOfTwo(int value) {
if (value < 0) {
throw new IllegalArgumentException("Given value:" + value + ". Expecting value >= 0.");
}
int n = -1 >>> Integer.numberOfLeadingZeros(value - 1);
return (n < 0) ? 1 : (n >= Ints.MAX_POWER_OF_TWO) ? Ints.MAX_POWER_OF_TWO : n + 1;
}
/**
* Returns a new Builder scoped to the given instances of the given job. A builder can only
* be scoped to a set of instances, a job, or a role once.
*
* @param jobKey The key identifying the job.
* @param instanceId An instance id of the target job.
* @param instanceIds Additional instance ids of the target job.
* @return A new Builder scoped to the given instance ids.
*/
public Builder byInstances(IJobKey jobKey, int instanceId, int... instanceIds) {
JobKeys.assertValid(jobKey);
return new Builder(
query.deepCopy()
.setRole(jobKey.getRole())
.setEnvironment(jobKey.getEnvironment())
.setJobName(jobKey.getName())
.setInstanceIds(ImmutableSet.<Integer>builder()
.add(instanceId)
.addAll(Ints.asList(instanceIds))
.build()));
}
/**
* Produces message format expected by Confluent platform: {@code <0x00><4 byte schema Id><avro message>}.
*/
byte[] encode(GenericRecord record) {
byte[] bytes = null;
try {
buffer.write(MAGIC_BYTE);
buffer.write(Ints.toByteArray(version));
writer.write(record, encoder);
encoder.flush();
bytes = buffer.toByteArray();
buffer.reset();
} catch (IOException unreachable) {}
return bytes;
}
@Override
public int readUnsignedShort() throws IOException {
byte b1 = readAndCheckByte();
byte b2 = readAndCheckByte();
return Ints.fromBytes((byte) 0, (byte) 0, b2, b1);
}
/**
* Reads an unsigned {@code short} as specified by {@link DataInputStream#readUnsignedShort()},
* except using little-endian byte order.
*
* @return the next two bytes of the input stream, interpreted as an unsigned 16-bit integer in
* little-endian byte order
* @throws IOException if an I/O error occurs
*/
@CanIgnoreReturnValue // to skip some bytes
@Override
public int readUnsignedShort() throws IOException {
byte b1 = readAndCheckByte();
byte b2 = readAndCheckByte();
return Ints.fromBytes((byte) 0, (byte) 0, b2, b1);
}
public void register(BreakerboxConfiguration breakerboxConfiguration) {
if (breakerboxConfiguration.getUrls().isEmpty()) {
return;
}
final TenacityPollingScheduler tenacityPollingScheduler = new TenacityPollingScheduler(
Ints.checkedCast(breakerboxConfiguration.getInitialDelay().toMilliseconds()),
Ints.checkedCast(breakerboxConfiguration.getDelay().toMilliseconds()),
true);
final CountDownLatch countDownLatch = new CountDownLatch(1);
if (breakerboxConfiguration.isWaitForInitialLoad()) {
tenacityPollingScheduler.addPollListener((eventType, lastResult, exception) -> countDownLatch.countDown());
}
final DynamicConfiguration dynConfig = new DynamicConfiguration(
new URLConfigurationSource(breakerboxConfiguration.getUrls().split(",")),
tenacityPollingScheduler);
ConfigurationManager.getConfigInstance();
ConfigurationManager.loadPropertiesFromConfiguration(dynConfig);
if (breakerboxConfiguration.isWaitForInitialLoad()) {
final Duration duration = breakerboxConfiguration.getWaitForInitialLoad();
try {
final boolean success = countDownLatch.await(duration.getQuantity(), duration.getUnit());
LOGGER.info("Breakerbox initial configuration load: {}", success ? "SUCCESS" : "FAILURE");
} catch (Exception err) {
LOGGER.warn("Failed waiting for Breakerbox initial load", err);
}
}
}
public ImmutableBitmap getImmutableBitmap()
{
final int sizePosition = initialOffset + offsetFromInitial + HEADER_NUM_BYTES + 2 * numDims * Floats.BYTES;
int numBytes = data.getInt(sizePosition);
data.position(sizePosition + Ints.BYTES);
ByteBuffer tmpBuffer = data.slice();
tmpBuffer.limit(numBytes);
return bitmapFactory.mapImmutableBitmap(tmpBuffer.asReadOnlyBuffer());
}
private int parseTimeout() {
String timeout = request.headers().get(Constants.HTTP_HEAD_READ_TIMEOUT);
if (timeout != null) {
request.headers().remove(Constants.HTTP_HEAD_READ_TIMEOUT);
Integer integer = Ints.tryParse(timeout);
if (integer != null && integer > 0) {
return integer;
}
}
return TIMEOUT;
}
@Override
protected Query newTermQuery(org.apache.lucene.index.Term term) {
String field = term.field();
String text = term.text();
FieldConfig.FieldType fieldType = indexConfig.getFieldTypeForIndexField(field);
if (IndexConfigUtil.isNumericOrDateFieldType(fieldType)) {
if (IndexConfigUtil.isDateFieldType(fieldType)) {
return getNumericOrDateRange(field, text, text, true, true);
}
else {
if (IndexConfigUtil.isNumericIntFieldType(fieldType) && Ints.tryParse(text) != null) {
return getNumericOrDateRange(field, text, text, true, true);
}
else if (IndexConfigUtil.isNumericLongFieldType(fieldType) && Longs.tryParse(text) != null) {
return getNumericOrDateRange(field, text, text, true, true);
}
else if (IndexConfigUtil.isNumericFloatFieldType(fieldType) && Floats.tryParse(text) != null) {
return getNumericOrDateRange(field, text, text, true, true);
}
else if (IndexConfigUtil.isNumericDoubleFieldType(fieldType) && Doubles.tryParse(text) != null) {
return getNumericOrDateRange(field, text, text, true, true);
}
}
return new MatchNoDocsQuery(field + " expects numeric");
}
return super.newTermQuery(term);
}
@Test(dataProvider = "spillEnabled")
public void testLastValuePartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit)
{
List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR)
.row("b", "A1", 1L, true, "")
.row("a", "A2", 1L, false, "")
.row("a", "B1", 2L, true, "")
.pageBreak()
.row("b", "C1", 2L, false, "")
.row("a", "C2", 3L, true, "")
.row("c", "A3", 1L, true, "")
.build();
DriverContext driverContext = createDriverContext(memoryLimit);
WindowOperatorFactory operatorFactory = createFactoryUnbounded(
ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR),
Ints.asList(0, 1, 2, 3),
LAST_VALUE,
Ints.asList(0),
Ints.asList(2),
ImmutableList.copyOf(new SortOrder[] {SortOrder.ASC_NULLS_LAST}),
spillEnabled);
MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR)
.row("a", "A2", 1L, false, "C2")
.row("a", "B1", 2L, true, "C2")
.row("a", "C2", 3L, true, "C2")
.row("b", "A1", 1L, true, "C1")
.row("b", "C1", 2L, false, "C1")
.row("c", "A3", 1L, true, "A3")
.build();
assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
public int readChecksum() throws IOException {
int b1 = in.read();
int b2 = in.read();
int b3 = in.read();
int b4 = in.read();
if ((b1 | b2 | b3 | b4) < 0) {
throw new EOFException();
}
hasher.putBytes(Util.INT0);
return Ints.fromBytes((byte) b1, (byte) b2, (byte) b3, (byte) b4);
}
@Override
public void initialize(CartesianProductConfigProto config) throws TezReflectionException {
this.sourceVertices = config.getSourcesList();
this.numPartitions = Ints.toArray(config.getNumPartitionsList());
this.minFraction = config.hasMinFraction() ? config.getMinFraction()
: CartesianProductVertexManager.TEZ_CARTESIAN_PRODUCT_SLOW_START_MIN_FRACTION_DEFAULT;
this.maxFraction = config.hasMaxFraction() ? config.getMaxFraction()
: CartesianProductVertexManager.TEZ_CARTESIAN_PRODUCT_SLOW_START_MAX_FRACTION_DEFAULT;
if (config.hasFilterClassName()) {
UserPayload userPayload = config.hasFilterUserPayload()
? UserPayload.create(ByteBuffer.wrap(config.getFilterUserPayload().toByteArray())) : null;
try {
filter = ReflectionUtils.createClazzInstance(config.getFilterClassName(),
new Class[]{UserPayload.class}, new UserPayload[]{userPayload});
} catch (TezReflectionException e) {
LOG.error("Creating filter failed");
throw e;
}
}
for (String sourceVertex : sourceVertices) {
sourceTaskCompleted.put(sourceVertex, new BitSet());
}
for (String vertex : getContext().getInputVertexEdgeProperties().keySet()) {
if (sourceVertices.indexOf(vertex) != -1) {
getContext().registerForVertexStateUpdates(vertex, EnumSet.of(VertexState.CONFIGURED));
numCPSrcNotInConfiguredState++;
} else {
getContext().registerForVertexStateUpdates(vertex, EnumSet.of(VertexState.RUNNING));
numBroadcastSrcNotInRunningState++;
}
}
getContext().vertexReconfigurationPlanned();
}
private void decompress(byte[] compressed) throws IOException
{
// uncompress
validBufferBytes = info.parameters.sstableCompressor.uncompress(compressed, 0, compressed.length - checksumBytes.length, buffer, 0);
totalCompressedBytesRead += compressed.length;
// validate crc randomly
if (info.parameters.getCrcCheckChance() > ThreadLocalRandom.current().nextDouble())
{
if (hasPostCompressionAdlerChecksums)
{
checksum.update(compressed, 0, compressed.length - checksumBytes.length);
}
else
{
checksum.update(buffer, 0, validBufferBytes);
}
System.arraycopy(compressed, compressed.length - checksumBytes.length, checksumBytes, 0, checksumBytes.length);
if (Ints.fromByteArray(checksumBytes) != (int) checksum.getValue())
throw new IOException("CRC unmatched");
// reset checksum object back to the original (blank) state
checksum.reset();
}
// buffer offset is always aligned
bufferOffset = current & ~(buffer.length - 1);
}
/**
* Detailed partition stats
*
* @param sizes actual partition sizes
*/
public static DetailedPartitionStatsProto
getDetailedPartitionStatsForPhysicalOutput(long[] sizes) {
DetailedPartitionStatsProto.Builder builder =
DetailedPartitionStatsProto.newBuilder();
for (int i=0; i<sizes.length; i++) {
// Round the size up. So 1 byte -> the value of sizeInMB == 1
// Throws IllegalArgumentException if value is greater than
// Integer.MAX_VALUE. That should be ok given Integer.MAX_VALUE * MB
// means PB.
int sizeInMb = Ints.checkedCast(ceil(sizes[i], MB));
builder.addSizeInMb(sizeInMb);
}
return builder.build();
}