// TODO: See if type safety can be improved here
    @SuppressWarnings("unchecked")
    public void read(DataInput in) throws IOException {

      this.methodName = StringRecord.readString(in);
      this.parameters = new IOReadableWritable[in.readInt()];
      this.parameterClasses = new Class[parameters.length];

      for (int i = 0; i < parameters.length; i++) {

        // Read class name for parameter and try to get class to that name
        final String className = StringRecord.readString(in);
        try {
          parameterClasses[i] = ClassUtils.getRecordByName(className);
        } catch (ClassNotFoundException cnfe) {
          throw new IOException(cnfe.toString());
        }

        // See if parameter is null
        if (in.readBoolean()) {
          try {
            final String parameterClassName = StringRecord.readString(in);
            final Class<? extends IOReadableWritable> parameterClass =
                ClassUtils.getRecordByName(parameterClassName);
            parameters[i] = parameterClass.newInstance();
          } catch (IllegalAccessException iae) {
            throw new IOException(iae.toString());
          } catch (InstantiationException ie) {
            throw new IOException(ie.toString());
          } catch (ClassNotFoundException cnfe) {
            throw new IOException(cnfe.toString());
          }
          // Object will do everything else on its own
          parameters[i].read(in);
        } else {
          parameters[i] = null;
        }
      }
    }
Exemplo n.º 2
0
  /**
   * Returns a reference to the {@link FileSystem} instance for accessing the file system identified
   * by the given {@link URI}.
   *
   * @param uri the {@link URI} identifying the file system
   * @return a reference to the {@link FileSystem} instance for accessing the file system identified
   *     by the given {@link URI}.
   * @throws IOException thrown if a reference to the file system instance could not be obtained
   */
  public static FileSystem get(final URI uri) throws IOException {

    FileSystem fs = null;

    synchronized (SYNCHRONIZATION_OBJECT) {
      if (uri.getScheme() == null) {
        throw new IOException("FileSystem: Scheme is null. file:// or hdfs:// are schemes.");
      }

      final FSKey key = new FSKey(uri.getScheme(), uri.getAuthority());

      // See if there is a file system object in the cache
      if (CACHE.containsKey(key)) {
        return CACHE.get(key);
      }

      // Try to create a new file system
      if (!FSDIRECTORY.containsKey(uri.getScheme())) {
        throw new IOException("No file system found with scheme " + uri.getScheme());
      }

      Class<? extends FileSystem> fsClass = null;
      try {
        fsClass = ClassUtils.getFileSystemByName(FSDIRECTORY.get(uri.getScheme()));
      } catch (ClassNotFoundException e1) {
        throw new IOException(StringUtils.stringifyException(e1));
      }

      try {
        fs = fsClass.newInstance();
      } catch (InstantiationException e) {
        throw new IOException(StringUtils.stringifyException(e));
      } catch (IllegalAccessException e) {
        throw new IOException(StringUtils.stringifyException(e));
      }

      // Initialize new file system object
      fs.initialize(uri);

      // Add new file system object to cache
      CACHE.put(key, fs);
    }

    return fs;
  }