Processes the class files from the currently running JDK,
using the jrt: filesystem.

@return true for success, false for failure
@throws IOException if an I/O error occurs
972235
boolean processSelf(Collection<String> classes) throws IOException {
        options.add("--add-modules");
        options.add("java.se.ee,jdk.xml.bind"); // TODO why jdk.xml.bind?

        if (classes.isEmpty()) {
            Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
                                      .getPath("/modules");

            // names are /modules/<modulename>/pkg/.../Classname.class
            try (Stream<Path> paths = Files.walk(modules)) {
                Stream<String> files =
                    paths.filter(p -> p.getNameCount() > 2)
                         .map(p -> p.subpath(1, p.getNameCount()))
                         .map(Path::toString);
                return doModularFileNames(files);
            }
        } else {
            return doClassNames(classes);
        }
    }
1324172
boolean processRelease(String release, Collection<String> classes) throws IOException {
        options.addAll(List.of("--release", release));

        if (release.equals("9")) {
            List<String> rootMods = List.of("java.se", "java.se.ee");
            TraverseProc proc = new TraverseProc(rootMods);
            JavaCompiler.CompilationTask task =
                compiler.getTask(null, fm, this,
                                 // options
                                 List.of("--add-modules", String.join(",", rootMods)),
                                 // classes
                                 List.of("java.lang.Object"),
                                 null);
            task.setProcessors(List.of(proc));
            if (!task.call()) {
                return false;
            }
            Map<PackageElement, List<TypeElement>> types = proc.getPublicTypes();
            options.add("--add-modules");
            options.add(String.join(",", rootMods));
            return doClassNames(
                types.values().stream()
                     .flatMap(List::stream)
                     .map(TypeElement::toString)
                     .collect(toList()));
        } else {
            // TODO: kind of a hack...
            // Create a throwaway compilation task with options "--release N"
            // which has the side effect of setting the file manager's
            // PLATFORM_CLASS_PATH to the right value.
            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
            StandardJavaFileManager fm =
                compiler.getStandardFileManager(this, null, StandardCharsets.UTF_8);
            JavaCompiler.CompilationTask task =
                compiler.getTask(null, fm, this, List.of("--release", release), null, null);
            List<Path> paths = new ArrayList<>();
            for (Path p : fm.getLocationAsPaths(StandardLocation.PLATFORM_CLASS_PATH)) {
                try (Stream<Path> str = Files.walk(p)) {
                    str.forEachOrdered(paths::add);
                }
            }

            options.add("-Xlint:-options");

            return doClassNames(
                paths.stream()
                     .filter(path -> path.toString().endsWith(".sig"))
                     .map(path -> path.subpath(1, path.getNameCount()))
                     .map(Path::toString)
                     .map(s -> s.replaceAll("\\.sig$", ""))
                     .map(s -> s.replace('/', '.'))
                     .collect(toList()));
        }
    }
83974
final public function processFile () : bool
	{
		// Validate the file
		if ($this->validateFile() == FALSE) return FALSE;
		// Set the attributes
		$this->setAttributes();
		// Validate the file depending on the file type.
		if ($this->validateType() == FALSE) return FALSE;
		// SUCCESS.
		return TRUE;
	}
15953
public Iterable<? extends CompilationUnitTree> parse() throws IOException {
        try {
            prepareCompiler();
            List<JCCompilationUnit> units = compiler.parseFiles(fileObjects);
            for (JCCompilationUnit unit: units) {
                JavaFileObject file = unit.getSourceFile();
                if (notYetEntered.containsKey(file))
                    notYetEntered.put(file, unit);
            }
            return units;
        }
        finally {
            parsed = true;
            if (compiler != null && compiler.log != null)
                compiler.log.flush();
        }
    }
655952
@Override
	public boolean process(final File inFile, final File outFile, final Dimensions outDims, final Logger logger) {
		return ExternalProcessUtils.executeProcess(getProcessBuilder(inFile, outFile, outDims), logger) == 0;
	}
188629
public void executeInstrumentation() throws IOException {
        errors.clear();

        // Iterate over all entries in the classes list
        for (File f : this.classFiles) {
            try {
                if (!f.canRead() || !f.canWrite()) {
                    throw new IOException(f + " can not be replaced");
                }
                instrumentClassFile(f);
            } catch (Exception e) {
                e.printStackTrace();
                errors.add(e);
            }
        }

        // Iterate over all entries in the jar list
        for (File f : this.jarFiles) {
            try {
                instrumentZipFile(f);
            } catch (Exception e) {
                e.printStackTrace();
                errors.add(e);
            }
        }

        // Chain the first exception and report the error count
        if (!errors.isEmpty()) {
            Throwable t = errors.get(0);
            IOException ioe = new IOException(errors.size() + " errors occurred");
            ioe.initCause(t);
            throw ioe;
        }
    }
549094
public synchronized boolean update()
        throws IOException
    {
        if (_resource!=null && !_resource.exists())
        {
            clear();
            return true;
        }
        
        long lm=_resource.lastModified();
        
        if (lm==_lastModified && (_buf!=null || _list!=null))
            return false;
        _lastModified=lm;
        
        if (_resource.isDirectory())
            _list=_resource.list();

        if (_list==null)
        {
            int l=(int)_resource.length();
            if (l<0)
                l=1024;
            ByteArrayOutputStream2 bout = new ByteArrayOutputStream2(l);
            InputStream in = _resource.getInputStream();
            try{IO.copy(in,bout);} finally {in.close();}
            _buf=bout.getBuf();
            if (_buf.length!=l)
                _buf=bout.toByteArray();
        }
        return true;
    }
995694
public void save() throws IOException {
        JFileChooser fc = FileChooser.getInstance();
        fc.setFileFilter(FileChooser.SimpleFileFilter.getWritableImageFIlter());
        fc.setAcceptAllFileFilterUsed(false);
        fc.setSelectedFiles(new File[0]);
        int returnVal = fc.showSaveDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            save(file);
        }        
    }
223295
@Override
  public synchronized Map<String, LocalResource> call() throws IOException {
    final Map<String, LocalResource> globalResources = new HashMap<>(1);
    if (!this.isUploaded){
      this.pathToGlobalJar = this.uploader.uploadToJobFolder(makeGlobalJar());
      this.isUploaded = true;
    }

    final LocalResource updatedGlobalJarResource = this.uploader.makeLocalResourceForJarFile(this.pathToGlobalJar);

    if (this.globalJarResource != null
        && this.globalJarResource.getTimestamp() != updatedGlobalJarResource.getTimestamp()) {
      LOG.log(Level.WARNING,
              "The global JAR LocalResource timestamp has been changed from "
              + this.globalJarResource.getTimestamp() + " to " + updatedGlobalJarResource.getTimestamp());
    }

    this.globalJarResource = updatedGlobalJarResource;

    // For now, always rewrite the information due to REEF-348
    globalResources.put(this.fileNames.getGlobalFolderPath(), updatedGlobalJarResource);

    return globalResources;
  }
710486
private void setClassPath() throws IOException {
    String fullPath = file.getAbsolutePath();
    String rootPath = fullPath.substring(0, fullPath.lastIndexOf(classFile.getRelativePath()));
    List<File> classPath = new ArrayList<>();
    classPath.add(new File(rootPath));
    parserEnv.fileManager().setLocation(StandardLocation.CLASS_PATH, classPath);
  }
282443
public boolean execute() throws IOException {
    if (stopOnError) {
      for (int i = 0; i < actions.length; i++) {
        if (!actions[i].execute()) {
          return false;
        }
      }

      return true;
    } else {
      boolean status = true;
      IOException exception = null;

      for (int i = 0; i < actions.length; i++) {
        try {
          status &= actions[i].execute();
        } catch (IOException ex) {
          status = false;

          if (exception == null) {
            exception = ex;
          }
        }
      }

      if (exception != null) {
        throw exception;
      }

      return status;
    }
  }
882400
public boolean processFile(Path srcPath, ParityFilePair parityPair,
      Decoder decoder, Boolean fromStripeStore, Context context) 
          throws IOException,
      InterruptedException {
    LOG.info("Processing file " + srcPath);
    Progressable progress = context;
    if (progress == null) {
      progress = RaidUtils.NULL_PROGRESSABLE;
    }
    
    DistributedFileSystem srcFs = getDFS(srcPath);
    FileStatus srcStat = srcFs.getFileStatus(srcPath);
    long blockSize = srcStat.getBlockSize();
    long srcFileSize = srcStat.getLen();
    String uriPath = srcPath.toUri().getPath();

    int numBlocksReconstructed = 0;
    List<LocatedBlockWithMetaInfo> lostBlocks = lostBlocksInFile(srcFs,
        uriPath, srcStat);
    if (lostBlocks.size() == 0) {
      LOG.warn("Couldn't find any lost blocks in file " + srcPath + 
          ", ignoring...");
      return false;
    }
    List<Block> blocksLostChecksum = new ArrayList<Block>();
    List<Block> blocksLostStripe = new ArrayList<Block>();
    
    for (LocatedBlockWithMetaInfo lb: lostBlocks) {
      Block lostBlock = lb.getBlock();
      long lostBlockOffset = lb.getStartOffset();

      LOG.info("Found lost block " + lostBlock +
          ", offset " + lostBlockOffset);
      Long oldCRC = decoder.retrieveChecksum(lostBlock, 
          srcPath, lostBlockOffset, srcFs, context);
      if (abortReconstruction(oldCRC, decoder)) {
        blocksLostChecksum.add(lostBlock);
        continue;
      }
      StripeInfo si = decoder.retrieveStripe(lostBlock, 
          srcPath, lostBlockOffset, srcFs, context, false);
      if (si == null && decoder.stripeStore != null) {
        blocksLostStripe.add(lostBlock);
        continue;
      }

      final long blockContentsSize =
        Math.min(blockSize, srcFileSize - lostBlockOffset);
      File localBlockFile =
        File.createTempFile(lostBlock.getBlockName(), ".tmp");
      localBlockFile.deleteOnExit();

      try {
        CRC32 crc = null;
        
        if (fromStripeStore) {
          crc = decoder.recoverBlockToFileFromStripeInfo(srcFs, srcPath,
              lostBlock, localBlockFile, blockSize,
              lostBlockOffset, blockContentsSize, si, context);
        } else {
          crc = decoder.recoverBlockToFile(srcFs, srcStat,
                        parityPair.getFileSystem(),
                        parityPair.getPath(), blockSize,
                        lostBlockOffset, localBlockFile,
                        blockContentsSize, si, context);
        }
        LOG.info("Recovered crc: " + ((crc == null)?null: crc.getValue()) +
            " expected crc:" + oldCRC);
        if (crc != null && oldCRC != null &&
            crc.getValue() != oldCRC) {
          // checksum doesn't match, it's dangerous to send it
          IOException ioe = new IOException("Block " + lostBlock.toString() +
              " new checksum " + crc.getValue() +
              " doesn't match the old one " + oldCRC);
          LogUtils.logRaidReconstructionMetrics(LOGRESULTS.FAILURE, 0,
              decoder.codec, srcPath, lostBlockOffset,
              LOGTYPES.OFFLINE_RECONSTRUCTION_CHECKSUM_VERIFICATION,
              srcFs, ioe, context);
          throw ioe;
        }
        // Now that we have recovered the file block locally, send it.
        computeMetadataAndSendReconstructedBlock(localBlockFile,
            lostBlock, blockContentsSize,
            lb.getLocations(),
            lb.getDataProtocolVersion(), 
            lb.getNamespaceID(), 
            progress);
        
        numBlocksReconstructed++;

      } finally {
        localBlockFile.delete();
      }
      progress.progress();
    }
    
    LOG.info("Reconstructed " + numBlocksReconstructed + " blocks in " + srcPath);
    checkLostBlocks(blocksLostChecksum, blocksLostStripe, srcPath, decoder.codec);
    return true;
  }
710088
public boolean open() throws IOException {
    if (!osFile.exists())
      throw new FileNotFoundException("File: " + osFile.getAbsolutePath());

    openChannel((int) osFile.length());

    OLogManager.instance().debug(this, "Checking file integrity of " + osFile.getName() + "...");

    init();

    final int fileSize = getFileSize();
    final int filledUpTo = getFilledUpTo();

    if (filledUpTo > 0 && filledUpTo > fileSize) {
      OLogManager
          .instance()
          .warn(
              this,
              "invalid filledUp value (%d) for file %s. Resetting the file size %d to the os file size: %d. Probably the file was not closed correctly last time",
              filledUpTo, getOsFile().getAbsolutePath(), fileSize, fileSize);
      setSize(fileSize);
    }

    if (filledUpTo > fileSize || filledUpTo < 0)
      OLogManager.instance().error(this, "Invalid filledUp size (=" + filledUpTo + "). The file could be corrupted", null,
          OStorageException.class);

    if (failCheck) {
      boolean softlyClosed = isSoftlyClosed();

      if (softlyClosed)
        setSoftlyClosed(false);

      return softlyClosed;
    }
    return true;
  }
443830
private void processClassWithByteCode( final Class< ? > clazz,
                                           final InputStream stream,
                                           final boolean includeFinalMethods ) throws IOException {

        final ClassReader reader = new ClassReader( stream );
        final ClassFieldVisitor visitor = new ClassFieldVisitor( clazz,
                                                                 includeFinalMethods,
                                                                 this );
        reader.accept( visitor,
                       0 );
        if ( clazz.getSuperclass() != null ) {
            final String name = getResourcePath( clazz.getSuperclass() );
            final InputStream parentStream = clazz.getResourceAsStream( name );
            if ( parentStream != null ) {
                try {
                    processClassWithByteCode( clazz.getSuperclass(),
                                              parentStream,
                                              includeFinalMethods );
                } finally {
                    parentStream.close();
                }
            } else {
                processClassWithoutByteCode( clazz.getSuperclass(),
                                             includeFinalMethods );
            }
        }
        if ( clazz.isInterface() ) {
            final Class< ? >[] interfaces = clazz.getInterfaces();
            for ( Class<?> anInterface : interfaces ) {
                final String name = getResourcePath( anInterface );
                final InputStream parentStream = clazz.getResourceAsStream( name );
                if ( parentStream != null ) {
                    try {
                        processClassWithByteCode( anInterface,
                                                  parentStream,
                                                  includeFinalMethods );
                    } finally {
                        parentStream.close();
                    }
                } else {
                    processClassWithoutByteCode( anInterface,
                                                 includeFinalMethods );
                }
            }
        }
    }
519847
private String process() throws IOException
    {
        final StringBuilder out = new StringBuilder();
        final Block parent = this.readLines();
        parent.removeSurroundingEmptyLines();

        this.recurse(parent, false);
        Block block = parent.blocks;
        while (block != null)
        {
            this.emitter.emit(out, block);
            block = block.next;
        }

        return out.toString();
    }
820819
public synchronized void start() throws IOException {
    Preconditions.checkState(mProcess == null, "Process is already running");
    String java = PathUtils.concatPath(System.getProperty("java.home"), "bin", "java");
    String classpath = System.getProperty("java.class.path");
    List<String> args = new ArrayList<>(Arrays.asList(java, "-cp", classpath));
    for (Entry<PropertyKey, String> entry : mConf.entrySet()) {
      args.add(String.format("-D%s=%s", entry.getKey().toString(), entry.getValue()));
    }
    args.add(mClazz.getCanonicalName());
    ProcessBuilder pb = new ProcessBuilder(args);
    pb.redirectError(mOutFile);
    pb.redirectOutput(mOutFile);
    mProcess = pb.start();
  }
214996
protected void processClass (File source)
    {
        CtClass clazz;
        InputStream in = null;
        try {
            clazz = _pool.makeClass(in = new BufferedInputStream(new FileInputStream(source)));
        } catch (IOException ioe) {
            System.err.println("Failed to load " + source + ": " + ioe);
            return;
        } finally {
            StreamUtil.close(in);
        }

        try {
            if (clazz.subtypeOf(_streamable)) {
                processStreamable(source, clazz);
            }
        } catch (NotFoundException nfe) {
            System.err.println("Error processing class [class=" + clazz.getName() +
                               ", error=" + nfe + "].");
        }
    }