Read and validate project file.

@param file input project file
@return project
321589
public ProjectBuilder read(final URI file) throws IOException {
        try (InputStream in = file.toURL().openStream()) {
            return read(in, file);
        }
    }
945536
public static ValidationResult isValidAddOn(Path file) {
		if (file == null || file.getNameCount() == 0) {
			return new ValidationResult(ValidationResult.Validity.INVALID_PATH);
		}

		if (!isAddOnFileName(file.getFileName().toString())) {
			return new ValidationResult(ValidationResult.Validity.INVALID_FILE_NAME);
		}

		if (!Files.isRegularFile(file) || !Files.isReadable(file)) {
			return new ValidationResult(ValidationResult.Validity.FILE_NOT_READABLE);
		}

		try (ZipFile zip = new ZipFile(file.toFile())) {
			ZipEntry manifest = zip.getEntry(MANIFEST_FILE_NAME);
			if (manifest == null) {
				return new ValidationResult(ValidationResult.Validity.MISSING_MANIFEST);
			}

			try (InputStream zis = zip.getInputStream(manifest)) {
				try {
					return new ValidationResult(new ZapAddOnXmlFile(zis));
				} catch (Exception e) {
					return new ValidationResult(ValidationResult.Validity.INVALID_MANIFEST, e);
				}
			}
		} catch (ZipException e) {
			return new ValidationResult(ValidationResult.Validity.UNREADABLE_ZIP_FILE, e);
		} catch (Exception e) {
			return new ValidationResult(ValidationResult.Validity.IO_ERROR_FILE, e);
		}
	}
1093434
public static byte[] readContent(File file) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            copy(new BufferedInputStream(new FileInputStream(file)), baos);
        } catch (FileNotFoundException e) {
            throw E.ioException(e);
        }
        return baos.toByteArray();
    }
565894
public Map<String, Object> processFile(File file) {
        ParserEngine engine = Engines.get(FileUtil.fileExt(file));
        if (engine==null) {
            LOGGER.error("Unable to find suitable markup engine for {}",file);
            return null;
        }

        return engine.parse(config, file);
    }
540040
public static String readFile(File file) {
		FileInputStream inputStream;
		try {
			inputStream = new FileInputStream(file);
			return new String(readStream(inputStream));
		} catch (FileNotFoundException e) {
			JK.throww(e);
			return null;
		}
	}
1323972
public FileInputStream getFileInputStream(final File file) throws FileNotFoundException {
        if (System.getSecurityManager() == null)
            return new FileInputStream(file);
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<FileInputStream>() {
                @Override
                public FileInputStream run() throws FileNotFoundException {
                    return new FileInputStream(file);
                }
            }, controlContext);
        } catch (PrivilegedActionException e) {
            if (e.getException() instanceof FileNotFoundException)
                throw (FileNotFoundException) e.getException();
            throw (RuntimeException) e.getException();
        }
    }
518012
private ProjectFile read() throws Exception
   {
      m_project = new ProjectFile();
      m_eventManager = m_project.getEventManager();

      ProjectConfig config = m_project.getProjectConfig();
      config.setAutoCalendarUniqueID(false);
      config.setAutoTaskID(false);
      config.setAutoTaskUniqueID(false);
      config.setAutoResourceUniqueID(false);
      config.setAutoWBS(false);
      config.setAutoOutlineNumber(false);

      m_project.getProjectProperties().setFileApplication("FastTrack");
      m_project.getProjectProperties().setFileType("FTS");

      m_eventManager.addProjectListeners(m_projectListeners);

      // processProject();
      // processCalendars();
      processResources();
      processTasks();
      processDependencies();
      processAssignments();

      return m_project;
   }
269166
public static Study readStudy(final File file) throws IOException {
        checkNotNull(file);
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            return readStudy(reader);
        }
    }
1228524
public void loadFile(File file)
   {
      try
      {
         m_projectFile = new UniversalProjectReader().read(file);
         if (m_projectFile == null)
         {
            throw new IllegalArgumentException("Unsupported file type");
         }
      }

      catch (Exception ex)
      {
         throw new RuntimeException(ex);
      }

      MpxjTreeNode projectNode = new MpxjTreeNode(m_projectFile, FILE_EXCLUDED_METHODS)
      {
         @Override public String toString()
         {
            return "Project";
         }
      };

      MpxjTreeNode configNode = new MpxjTreeNode(m_projectFile.getProjectConfig())
      {
         @Override public String toString()
         {
            return "MPXJ Configuration";
         }
      };
      projectNode.add(configNode);

      MpxjTreeNode propertiesNode = new MpxjTreeNode(m_projectFile.getProjectProperties())
      {
         @Override public String toString()
         {
            return "Properties";
         }
      };
      projectNode.add(propertiesNode);

      MpxjTreeNode tasksFolder = new MpxjTreeNode("Tasks");
      projectNode.add(tasksFolder);
      addTasks(tasksFolder, m_projectFile);

      MpxjTreeNode resourcesFolder = new MpxjTreeNode("Resources");
      projectNode.add(resourcesFolder);
      addResources(resourcesFolder, m_projectFile);

      MpxjTreeNode assignmentsFolder = new MpxjTreeNode("Assignments");
      projectNode.add(assignmentsFolder);
      addAssignments(assignmentsFolder, m_projectFile);

      MpxjTreeNode calendarsFolder = new MpxjTreeNode("Calendars");
      projectNode.add(calendarsFolder);
      addCalendars(calendarsFolder, m_projectFile);

      MpxjTreeNode groupsFolder = new MpxjTreeNode("Groups");
      projectNode.add(groupsFolder);
      addGroups(groupsFolder, m_projectFile);

      MpxjTreeNode customFieldsFolder = new MpxjTreeNode("Custom Fields");
      projectNode.add(customFieldsFolder);
      addCustomFields(customFieldsFolder, m_projectFile);

      MpxjTreeNode filtersFolder = new MpxjTreeNode("Filters");
      projectNode.add(filtersFolder);

      MpxjTreeNode taskFiltersFolder = new MpxjTreeNode("Task Filters");
      filtersFolder.add(taskFiltersFolder);
      addFilters(taskFiltersFolder, m_projectFile.getFilters().getTaskFilters());

      MpxjTreeNode resourceFiltersFolder = new MpxjTreeNode("Resource Filters");
      filtersFolder.add(resourceFiltersFolder);
      addFilters(resourceFiltersFolder, m_projectFile.getFilters().getResourceFilters());

      MpxjTreeNode viewsFolder = new MpxjTreeNode("Views");
      projectNode.add(viewsFolder);
      addViews(viewsFolder, m_projectFile);

      MpxjTreeNode tablesFolder = new MpxjTreeNode("Tables");
      projectNode.add(tablesFolder);
      addTables(tablesFolder, m_projectFile);

      m_model.setRoot(projectNode);
   }
1343831
public static InputStream inputStream(File file) {
        // workaround http://stackoverflow.com/questions/36880692/java-file-does-not-exists-but-file-getabsolutefile-exists
        if (!file.exists()) {
            file = file.getAbsoluteFile();
        }
        if (!file.exists()) {
            throw E.ioException("File does not exists: %s", file.getPath());
        }
        try {
            return new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw E.ioException(e);
        }
    }
6937
public static FileValue fileValue(File file){
    String contentType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(file);
    return new FileValueBuilderImpl(file.getName()).file(file).mimeType(contentType).create();
  }
534267
public static String readFile(File file, long start, int length) throws IOException {
        byte[] bs = new byte[length];
        try (FileInputStream fis = new FileInputStream(file)) {
            fis.skip(start);
            fis.read(bs);
        }
        return new String(bs);
    }
955955
public InputStream load(String folder, String file) throws IOException {
      if (content.containsKey(folder+"/"+file))
        return new ByteArrayInputStream(content.get(folder+"/"+file));
      else {
        File f = new File(Utilities.path(path, folder, file));
        if (f.exists())
          return new FileInputStream(f);
        throw new IOException("Unable to find the file "+folder+"/"+file+" in the package "+name());
      }
    }
461051
public FileDigestOutputStream openFile(File file) throws IOException
   {
      MessageDigest md;
      try
      {
         md = MessageDigest.getInstance(digestAlgo);
      }
      catch (NoSuchAlgorithmException e)
      {
         LOG.error("Can't wriet using " + digestAlgo + " algorithm, " + e, e);
         throw new IOException(e.getMessage(), e);
      }

      return new FileDigestOutputStream(file, md);
   }
911626
public static Exception checkFile(final File file)
	{
		Exception ex = null;
		String error = null;
		// check if the file does not exists...
		if (!file.exists())
		{
			error = "The " + file + " does not exists.";
			ex = new FileDoesNotExistException(error);
			return ex;
		}
		// check if the file is not a directory...
		if (!file.isDirectory())
		{
			error = "The " + file + " is not a directory.";
			ex = new FileIsNotADirectoryException(error);
			return ex;
		}

		final File[] ff = file.listFiles();
		// If the file is null
		if (ff == null)
		{ // it is security restricted
			error = "The " + file + " could not list the content.";
			ex = new DirectoryHasNoContentException(error);
		}
		return ex;
	}
738560
private S getInputStreamForFile(File file) throws IOException {
        assert file != null : "File must be specified";
        return this.getInputStreamForRawStream(new FileInputStream(file));
    }
1339249
private List<String> readFile(File file) throws Exception {
        List<String> content = new ArrayList<>(100);
        try (BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) {
            String line;
            while ((line = is.readLine()) != null) {
                content.add(line);
            }
            return content;
        }
    }