Exemplo n.º 1
0
 public DescriptorMap setHost(Host host) {
   Util.throwIfNull(host);
   Util.throwIfNot(this.mIsInitializing);
   Util.throwIfNotNull(this.mHost);
   this.mHost = host;
   return this;
 }
  public void bind(LocalSocket socket, HttpParams params) throws IOException {
    Util.throwIfNull(socket);
    Util.throwIfNull(params);

    mSocket = socket;

    int bufferSize = HttpConnectionParams.getSocketBufferSize(params);

    mInputBuffer = new LocalSocketSessionInputBuffer(socket, bufferSize, params);
    init(mInputBuffer, new LocalSocketSessionOutputBuffer(socket, bufferSize, params), params);

    mOpen = true;
  }
Exemplo n.º 3
0
 public DescriptorMap endInit() {
   Util.throwIfNot(this.mIsInitializing);
   Util.throwIfNull(this.mHost);
   this.mIsInitializing = false;
   for (Class cls : this.mMap.keySet()) {
     Descriptor descriptor = (Descriptor) this.mMap.get(cls);
     if (descriptor instanceof ChainedDescriptor) {
       ((ChainedDescriptor) descriptor).setSuper(getImpl(cls.getSuperclass()));
     }
     descriptor.initialize(this.mHost);
   }
   return this;
 }
Exemplo n.º 4
0
 public DescriptorMap register(Class<?> cls, Descriptor descriptor) {
   Util.throwIfNull(cls);
   Util.throwIfNull(descriptor);
   Util.throwIf(descriptor.isInitialized());
   Util.throwIfNot(this.mIsInitializing);
   if (this.mMap.containsKey(cls)) {
     throw new UnsupportedOperationException();
   } else if (this.mMap.containsValue(descriptor)) {
     throw new UnsupportedOperationException();
   } else {
     this.mMap.put(cls, descriptor);
     return this;
   }
 }
Exemplo n.º 5
0
 /**
  * Flatten all columns and all rows of a cursor to a single array. The array cannot be interpreted
  * meaningfully without the number of columns.
  *
  * @param cursor
  * @param limit Maximum number of rows to process.
  * @return List of Java primitives matching the value type of each column.
  */
 private List<Object> flattenRows(Cursor cursor, int limit) {
   Util.throwIfNot(limit >= 0);
   List<Object> flatList = new ArrayList<Object>();
   final int numColumns = cursor.getColumnCount();
   for (int row = 0; row < limit && cursor.moveToNext(); row++) {
     for (int column = 0; column < numColumns; column++) {
       switch (cursor.getType(column)) {
         case Cursor.FIELD_TYPE_NULL:
           flatList.add(null);
           break;
         case Cursor.FIELD_TYPE_INTEGER:
           flatList.add(cursor.getLong(column));
           break;
         case Cursor.FIELD_TYPE_FLOAT:
           flatList.add(cursor.getDouble(column));
           break;
         case Cursor.FIELD_TYPE_BLOB:
           flatList.add(cursor.getBlob(column));
           break;
         case Cursor.FIELD_TYPE_STRING:
         default:
           flatList.add(cursor.getString(column));
           break;
       }
     }
   }
   if (!cursor.isAfterLast()) {
     for (int column = 0; column < numColumns; column++) {
       flatList.add("{truncated}");
     }
   }
   return flatList;
 }
 @Override
 public void setSocketTimeout(int timeout) {
   try {
     mSocket.setSoTimeout(timeout);
   } catch (IOException e) {
     Util.throwIfNot(mSocket.isClosed());
   }
 }
 @Override
 public int getSocketTimeout() {
   try {
     return mSocket.getSoTimeout();
   } catch (IOException e) {
     Util.throwIfNot(mSocket.isClosed());
     return -1;
   }
 }
 public byte[] clearCurrentBuffer() {
   ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   try {
     while (hasBufferedData()) {
       int b = read();
       Util.throwIfNot(b != -1, "Buffered data cannot EOF");
       buffer.write(b);
     }
     return buffer.toByteArray();
   } catch (IOException e) {
     // This shouldn't be possible.
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 9
0
 /**
  * Enable use of the {@code dumpapp} system. This is an extension to Stetho which allows
  * developers to configure custom debug endpoints as tiny programs embedded inside of a larger
  * running Android application. Examples of this would be simple utilities to visualize and edit
  * {@link SharedPreferences} data, kick off sync or other background tasks, inject custom data
  * temporarily into the process for debugging/reproducibility, upload error reports, etc.
  *
  * <p>See {@code ./scripts/dumpapp} for more information on how to use this system once enabled.
  *
  * @param plugins The set of plugins to use.
  */
 public InitializerBuilder enableDumpapp(DumperPluginsProvider plugins) {
   mDumperPlugins = Util.throwIfNull(plugins);
   return this;
 }
 @Override
 protected void assertOpen() throws IllegalStateException {
   Util.throwIfNot(mOpen);
 }
Exemplo n.º 11
0
 public Descriptor get(Class<?> cls) {
   Util.throwIfNull(cls);
   Util.throwIf(this.mIsInitializing);
   return getImpl(cls);
 }
Exemplo n.º 12
0
 public DescriptorMap beginInit() {
   Util.throwIf(this.mIsInitializing);
   this.mIsInitializing = true;
   return this;
 }