This assume that the primary file exists.

@param showError
@return
14275
private PrintStream getPrimaryStream(boolean showError) {
        File primaryFile = getPrimaryFile();
        setStreamFromFile(primaryFile, false, primaryFile.length(), showError);
        return currentPrintStream;
    }
610946
private static synchronized String getFile(String name) {
        if(Objects.isNullOrEmpty(baseDirectory)){
            baseDirectory = Options.getStorage().getSystem("numberSequence.home", System.getProperty("user.home") + File.separator + ".s1-sequences");
        }
        File dir = new File(baseDirectory);
        if(!dir.exists())
            dir.mkdirs();
        if(!dir.isDirectory())
            throw new S1SystemError("Directory error: "+baseDirectory);
        return dir.getAbsolutePath()+File.separator+name;
    }
481790
private InputStream getErrorStream() {
        InputStream errorStream = this.connection.getErrorStream();
        if (errorStream != null) {
            final String contentEncoding = this.connection.getContentEncoding();
            if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
                try {
                    errorStream = new GZIPInputStream(errorStream);
                } catch (IOException e) {
                    // just return the error stream as is
                }
            }
        }

        return errorStream;
    }
1212555
@Nonnull
  public static FileIOError deleteDirRecursiveIfExisting (@Nonnull final Path aDir)
  {
    final FileIOError aError = deleteDirRecursive (aDir);
    if (aError.getErrorCode ().equals (EFileIOErrorCode.SOURCE_DOES_NOT_EXIST))
      return aError.withoutErrorCode ();
    return aError;
  }
1323164
@PreAuthorize("isAuthenticated()")
    public E uploadFile(MultipartFile file) throws Exception {

        if (file == null) {
            final String errMsg = "Upload failed. File is null.";
            LOG.error(errMsg);
            throw new Exception(errMsg);
        } else if (file.isEmpty()) {
            final String errMsg = "Upload failed. File is empty.";
            LOG.error(errMsg);
            throw new Exception(errMsg);
        }

        InputStream is = null;
        byte[] fileByteArray = null;
        E fileToPersist = getEntityClass().newInstance();

        try {
            is = file.getInputStream();
            fileByteArray = IOUtils.toByteArray(is);
        } catch (Exception e) {
            throw new Exception("Could not create the bytearray: " + e.getMessage());
        } finally {
            IOUtils.closeQuietly(is);
        }

        fileToPersist.setFile(fileByteArray);
        fileToPersist.setFileType(file.getContentType());
        fileToPersist.setFileName(file.getOriginalFilename());

        dao.saveOrUpdate(fileToPersist);

        return fileToPersist;
    }
20037
public File asFile(String fileName) throws HelloSignException {
        Integer lastResponseCode = getLastResponseCode();
        File f = null;
        try {
            if (lastResponseCode != null && lastResponseCode != HttpURLConnection.HTTP_OK) {
                this.asJson(); // Will validate response
            }
            f = createTemporaryFile(fileName);
            if (getLastResponseAsFile(f) == 0) {
                logger.warn("No bytes written to file: " + fileName);
            }
        } catch (HelloSignException ex) {
            throw ex;
        } finally {
            reset();
        }
        return f;
    }
236022
@Nonnull
  public static FileIOError renameDir (@Nonnull final Path aSourceDir, @Nonnull final Path aTargetDir)
  {
    ValueEnforcer.notNull (aSourceDir, "SourceDirectory");
    ValueEnforcer.notNull (aTargetDir, "TargetDirectory");

    final Path aRealSourceDir = _getUnifiedPath (aSourceDir);
    final Path aRealTargetDir = _getUnifiedPath (aTargetDir);

    // Does the source directory exist?
    if (!aRealSourceDir.toFile ().isDirectory ())
      return EFileIOErrorCode.SOURCE_DOES_NOT_EXIST.getAsIOError (EFileIOOperation.RENAME_DIR, aRealSourceDir);

    // Are source and target different?
    if (EqualsHelper.equals (aRealSourceDir, aRealTargetDir))
      return EFileIOErrorCode.SOURCE_EQUALS_TARGET.getAsIOError (EFileIOOperation.RENAME_DIR, aRealSourceDir);

    // Does the target directory already exist?
    if (aRealTargetDir.toFile ().exists ())
      return EFileIOErrorCode.TARGET_ALREADY_EXISTS.getAsIOError (EFileIOOperation.RENAME_DIR, aRealTargetDir);

    // Is the source a parent of target?
    if (PathHelper.isParentDirectory (aRealSourceDir, aRealTargetDir))
      return EFileIOErrorCode.TARGET_IS_CHILD_OF_SOURCE.getAsIOError (EFileIOOperation.RENAME_DIR,
                                                                      aRealSourceDir,
                                                                      aRealTargetDir);

    // Is the source parent directory writable?
    final Path aSourceParentDir = aRealSourceDir.getParent ();
    if (aSourceParentDir != null && !Files.isWritable (aSourceParentDir))
      return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_DIR, aRealSourceDir);

    // Is the target parent directory writable?
    final Path aTargetParentDir = aRealTargetDir.getParent ();
    if (aTargetParentDir != null && aTargetParentDir.toFile ().exists () && !Files.isWritable (aTargetParentDir))
      return EFileIOErrorCode.TARGET_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_DIR, aRealTargetDir);

    // Ensure parent of target directory is present
    PathHelper.ensureParentDirectoryIsPresent (aRealTargetDir);

    return _perform (EFileIOOperation.RENAME_DIR, PathOperations::_atomicMove, aRealSourceDir, aRealTargetDir);
  }
1291880
@Override
    protected File getFileForLastModifiedCheck() throws IOException {
        URL url = getURL();
        if (ResourceUtils.isJarURL(url)) {
            URL actualUrl = ResourceUtils.extractArchiveURL(url);
            return ResourceUtils.getFile(actualUrl, "Jar URL");
        } else {
            return getFile();
        }
    }
1166381
long getAckEpoch() throws IOException {
    try {
      long ackEpoch = FileUtils.readLongFromFile(this.fAckEpoch);
      return ackEpoch;
    } catch (FileNotFoundException e) {
      LOG.debug("File not exist, initialize acknowledged epoch to -1");
      return -1;
    } catch (IOException e) {
      LOG.error("IOException encountered when access acknowledged epoch");
      throw e;
    }
  }
1234572
public static RefCountedBufferingFileStream openNew(
			final FunctionWithException<File, RefCountedFile, IOException> tmpFileProvider) throws IOException {

		return new RefCountedBufferingFileStream(
				tmpFileProvider.apply(null),
				BUFFER_SIZE);
	}
779869
private InputStream asInputStream() {
        InputStream inputStream = classLoader.getResourceAsStream(path);
        if (inputStream == null) {
            throw new RuntimeException("File '" + path + "' was not found.");
        }
        return inputStream;
    }
1348257
public File getFile()
   {
      File file = (File)this.getSource();
      
      if(file != null)
          FileMonitor.waitFor(file);
      
      return file;
  
   }
154091
public static InputStream fileAsStream(File file) {
    try {
      return new BufferedInputStream(new FileInputStream(file));
    } catch(FileNotFoundException e) {
      throw LOG.fileNotFoundException(file.getAbsolutePath(), e);
    }
  }
1116832
public boolean hasStream(SIBUuid12 streamID, int priority, Reliability reliability ) throws SIResourceException 
  {
    if (tc.isEntryEnabled()) 
      SibTr.entry(tc, "hasStream", 
        new Object[]{streamID, new Integer(priority), reliability});
        
    StreamSet streamSet = (StreamSet) streamSets.get(streamID);
    if(streamSet != null) 
    {
      if ( streamSet.getStream(priority, reliability) != null )        
      { 
        if (tc.isEntryEnabled()) SibTr.exit(tc, "hasStream", Boolean.TRUE);
        return true;
      }  
    }
    if (tc.isEntryEnabled()) SibTr.exit(tc, "hasStream", Boolean.FALSE);
    return false;  
  }
679872
@Nonnull
  public static FileIOError createDir (@Nonnull final Path aDir)
  {
    ValueEnforcer.notNull (aDir, "Directory");

    final Path aRealDir = _getUnifiedPath (aDir);
    return FileOperations.createDir (aRealDir.toFile ());

    // // Does the directory already exist?
    // if (Files.exists (aRealDir))
    // return EFileIOErrorCode.TARGET_ALREADY_EXISTS.getAsIOError
    // (EFileIOOperation.CREATE_DIR, aRealDir);
    //
    // // Is the parent directory writable?
    // final Path aParentDir = aRealDir.getParent ();
    // if (aParentDir != null && Files.exists (aParentDir) && !Files.isWritable
    // (aParentDir))
    // return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError
    // (EFileIOOperation.CREATE_DIR, aRealDir);
    //
    // return _perform (EFileIOOperation.CREATE_DIR, Files::createDirectory,
    // aRealDir);
  }
949697
def _showError(self, msg="", title="Error"):
        
        self.errorWidget.setError(msg=msg, title=title)
343810
@Nonnull
  public static FileIOError renameDir (@Nonnull final File aSourceDir, @Nonnull final File aTargetDir)
  {
    ValueEnforcer.notNull (aSourceDir, "SourceDirectory");
    ValueEnforcer.notNull (aTargetDir, "TargetDirectory");

    // Does the source directory exist?
    if (!FileHelper.existsDir (aSourceDir))
      return EFileIOErrorCode.SOURCE_DOES_NOT_EXIST.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir);

    // Are source and target different?
    if (EqualsHelper.equals (aSourceDir, aTargetDir))
      return EFileIOErrorCode.SOURCE_EQUALS_TARGET.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir);

    // Does the target directory already exist?
    if (aTargetDir.exists ())
      return EFileIOErrorCode.TARGET_ALREADY_EXISTS.getAsIOError (EFileIOOperation.RENAME_DIR, aTargetDir);

    // Is the source a parent of target?
    if (FileHelper.isParentDirectory (aSourceDir, aTargetDir))
      return EFileIOErrorCode.TARGET_IS_CHILD_OF_SOURCE.getAsIOError (EFileIOOperation.RENAME_DIR,
                                                                      aSourceDir,
                                                                      aTargetDir);

    // Is the source parent directory writable?
    final File aSourceParentDir = aSourceDir.getParentFile ();
    if (aSourceParentDir != null && !aSourceParentDir.canWrite ())
      return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir);

    // Is the target parent directory writable?
    final File aTargetParentDir = aTargetDir.getParentFile ();
    if (aTargetParentDir != null && aTargetParentDir.exists () && !aTargetParentDir.canWrite ())
      return EFileIOErrorCode.TARGET_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_DIR, aTargetDir);

    // Ensure parent of target directory is present
    FileHelper.ensureParentDirectoryIsPresent (aTargetDir);

    try
    {
      final EFileIOErrorCode eError = aSourceDir.renameTo (aTargetDir) ? EFileIOErrorCode.NO_ERROR
                                                                       : EFileIOErrorCode.OPERATION_FAILED;
      return eError.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir, aTargetDir);
    }
    catch (final SecurityException ex)
    {
      return EFileIOErrorCode.getSecurityAsIOError (EFileIOOperation.RENAME_DIR, ex);
    }
  }