List of usage examples for com.google.common.base Preconditions checkState
public static void checkState(boolean expression)
From source file:org.sonar.java.ast.visitors.FileVisitor.java
@Override public void leaveFile(AstNode astNode) { Preconditions.checkState(getContext().peekSourceCode().isType(SourceFile.class)); getContext().popSourceCode(); }
From source file:com.buaa.cfs.fs.ByteBufferUtil.java
/** * Perform a fallback read.//from w w w. j a va2s . c o m */ public static ByteBuffer fallbackRead(InputStream stream, ByteBufferPool bufferPool, int maxLength) throws IOException { if (bufferPool == null) { throw new UnsupportedOperationException("zero-copy reads " + "were not available, and you did not provide a fallback " + "ByteBufferPool."); } boolean useDirect = streamHasByteBufferRead(stream); ByteBuffer buffer = bufferPool.getBuffer(useDirect, maxLength); if (buffer == null) { throw new UnsupportedOperationException( "zero-copy reads " + "were not available, and the ByteBufferPool did not provide " + "us with " + (useDirect ? "a direct" : "an indirect") + "buffer."); } Preconditions.checkState(buffer.capacity() > 0); Preconditions.checkState(buffer.isDirect() == useDirect); maxLength = Math.min(maxLength, buffer.capacity()); boolean success = false; try { if (useDirect) { buffer.clear(); buffer.limit(maxLength); ByteBufferReadable readable = (ByteBufferReadable) stream; int totalRead = 0; while (true) { if (totalRead >= maxLength) { success = true; break; } int nRead = readable.read(buffer); if (nRead < 0) { if (totalRead > 0) { success = true; } break; } totalRead += nRead; } buffer.flip(); } else { buffer.clear(); int nRead = stream.read(buffer.array(), buffer.arrayOffset(), maxLength); if (nRead >= 0) { buffer.limit(nRead); success = true; } } } finally { if (!success) { // If we got an error while reading, or if we are at EOF, we // don't need the buffer any more. We can give it back to the // bufferPool. bufferPool.putBuffer(buffer); buffer = null; } } return buffer; }
From source file:org.b1.pack.cli.FsFileContent.java
@Override public void writeTo(OutputStream stream, long start, Long end) throws IOException { System.out.println("Adding " + file); long length = (end != null ? end : file.length()) - start; InputSupplier<InputStream> slice = ByteStreams.slice(Files.newInputStreamSupplier(file), start, length); Preconditions.checkState(ByteStreams.copy(slice, stream) == length); }
From source file:com.cloudera.impala.analysis.AlterTableRenameStmt.java
public AlterTableRenameStmt(TableName oldTableName, TableName newTableName) { super(oldTableName); Preconditions.checkState(newTableName != null && !newTableName.isEmpty()); this.newTableName = newTableName; }
From source file:org.easy.ldap.ServiceFactory.java
/** * Creates service for LDAP CRUD operations * //from w ww.j ava 2s.com * @param properties * - LDAP connection and structure properties. * @return */ public LdapAdminService createAdminService() { Preconditions.checkState(properties != null); return new AdminServiceImpl(properties); }
From source file:com.cloudera.impala.analysis.AlterTableDropColStmt.java
public AlterTableDropColStmt(TableName tableName, String colName) { super(tableName); Preconditions.checkState(colName != null && !colName.isEmpty()); colName_ = colName; }
From source file:com.threerings.tools.gxlate.UploadMojo.java
@Override protected void run() throws Exception { Preconditions.checkState(keysFound.isEmpty()); if (checkOnly()) { getLog().info("Comparing English strings to spreadsheet and reporting differences. " + "No changes will be made."); }//from w ww. j av a 2 s .co m Document doc = new Document(); Set<Integer> unused = Sets.newHashSet(); for (PropsFile source : loadAllProps()) { Table table = doc.loadTable(Bundle.baseName(source.getFile().getName())); Index index = new Index(table, Field.ID.getColumnName()); for (Domain.Row genRow : getFilteredRows(source)) { if (genRow.status == Rules.Status.IGNORE || genRow.status == Rules.Status.OMIT) { continue; } String error = DefaultTranslator.checkBraces(genRow.fields.english(), unused); if (error != null) { getLog().error(String.format("String %s %s", genRow.fields.id(), error)); failures.add(new Exception(genRow.fields.id())); continue; } handleRow(table, index, genRow); } if (table.needsRefresh()) { getLog().info("Refreshing table to incorporate added rows"); try { // TODO: add support for the index being refreshed somewhere table.refreshAddedRows(); } catch (Exception ex) { getLog().error("Refresh failed", ex); failures.add(ex); } } if (removeRows) { doRemovals(table, index); } } }
From source file:com.google.template.soy.sharedpasses.render.CountingFlushableAppendable.java
public CountingFlushableAppendable(Appendable appendable) { Preconditions.checkState(appendable instanceof Flushable); this.appendable = appendable; this.flushable = (Flushable) appendable; }
From source file:com.moz.fiji.schema.util.JvmId.java
/** * Returns the Unix process ID of this JVM. * * @return the Unix process ID of this JVM. *///from w ww .j a v a2 s . com public static int getPid() { try { final Process process = new ProcessBuilder("/bin/sh", "-c", "echo $PPID").start(); try { Preconditions.checkState(process.waitFor() == 0); } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie); } final String pidStr = IOUtils.toString(process.getInputStream()).trim(); return Integer.parseInt(pidStr); } catch (IOException ioe) { throw new FijiIOException(ioe); } }
From source file:io.divolte.server.filesinks.gcs.DynamicDelegatingOutputStream.java
public void attachDelegate(final OutputStream newDelegate) { Preconditions.checkState(wrapped == null); wrapped = Objects.requireNonNull(newDelegate); }