Check input file integrity.

@param name
the name of the file
@param inFile
the file
965203
private static void checkInputFile(final String name, final File inFile) {

    String isFailure = null;

    if (inFile.isDirectory()) {
      isFailure = "The " + name + " file is a directory!";
    } else if (!inFile.exists()) {
      isFailure = "The " + name + " file does not exist!";
    } else if (!inFile.canRead()) {
      isFailure = "No permissions to read the " + name + " file!";
    }

    if (null != isFailure) {
      throw new TerminateToolException(-1,
          isFailure + " Path: " + inFile.getAbsolutePath());
    }
  }
1290423
protected boolean checksumsMatch(File localFile, String remoteChecksum)
        throws IOException {
        if (remoteChecksum == null || "".equals(remoteChecksum)) {
            if (contentStream != null) {
                remoteChecksum = contentStream.getChecksum();
            } else {
                remoteChecksum = source.getSourceChecksum(contentItem);
            }
        }
        String localChecksum = getChecksum(localFile);
        return localChecksum.equals(remoteChecksum);
    }
119853
public static void makeFileAndClose(InputStream in, String outputFilename) {
        final byte[] bytes = toBytesAndClose(in);
        final File outputFile = new File(outputFilename);
        final FileOutputStream fileOutputStream;
        try {
            fileOutputStream = new FileOutputStream(outputFile, false);
        } catch (FileNotFoundException e) {
            String msg = "new FileOutputStream(outputFile, false) threw the " + e.getClass().getSimpleName();
            msg = msg + ": outputFilename=" + outputFilename;
            throw new IllegalStateException(msg, e);
        }
        try {
            fileOutputStream.write(bytes);
        } catch (IOException e) {
            String msg = "fileOutputStream.write(toBytes) threw the " + e.getClass().getSimpleName();
            msg = msg + ": outputFilename=" + outputFilename;
            throw new IllegalStateException(msg, e);
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException ignored) {}
        }
    }
342594
public static void copy(File sourceFile, File targetFile) throws IOException {
	FileInputStream in = new FileInputStream(sourceFile);
	try {
	    FileOutputStream out = new FileOutputStream(targetFile);
	    try {
		copy(in, out);
	    } finally {
		out.close();
	    }
	} finally {
	    in.close();
	}
    }
92520
private void verifyFile(String[] args, int startIndex) {
    Path root = null;
    if (args.length <= startIndex) {
      throw new IllegalArgumentException("too few arguments");
    }
    String arg = args[startIndex];
    root = new Path(arg);
    try {
      FileSystem fs = root.getFileSystem(conf);
      // Make sure default uri is the same as root  
      conf.set(FileSystem.FS_DEFAULT_NAME_KEY, fs.getUri().toString());
      FileVerifier fv = new FileVerifier(conf);
      fv.verifyFile(root, System.out);
    } catch (IOException ex) {
      System.err.println("verifyFile: " + ex);
    }
  }
870206
function verifyFileName (fileName)
{
    // if fileName undefined or null, throw exception
    if ((fileName === undefined) || (fileName === null)) {
        var message1 = format (cc.MSG_INVALID_NAME);
        throw new SafeFileError (cc.INVALID_NAME, message1);
    }
}
998332
public static void check(String fileOrUrl) throws IOException, TrustyUriException {
		CheckFile c;
		try {
			URL url = new URL(fileOrUrl);
			c = new CheckFile(url);
		} catch (MalformedURLException ex) {
			c = new CheckFile(new File(fileOrUrl));
		}

		boolean valid = c.check();
		if (valid) {
			System.out.println("Correct hash: " + c.r.getArtifactCode());
			//System.out.println("ni URI: " + TrustyUriUtils.getNiUri(fileName));
		} else {
			System.out.println("*** INCORRECT HASH ***");
		}
	}
1191908
private void openInputFile(final String inputFileName) throws IOException
	{
		myInputFile = new File(inputFileName);
		myInputStream = new FileInputStream(myInputFile);
		myStreamReader = new InputStreamReader(myInputStream, getInputEncodingCode());
		myBufferedReader = new BufferedReader(myStreamReader);
		myLineReader = new LineNumberReader(myBufferedReader);
	}
247574
public void setMetadata(String moduleKeyWithBranch, final DefaultInputFile inputFile, Charset defaultEncoding) {
    CharsetDetector charsetDetector = new CharsetDetector(inputFile.path(), defaultEncoding);
    try {
      Charset charset;
      if (charsetDetector.run()) {
        charset = charsetDetector.charset();
      } else {
        LOG.debug("Failed to detect a valid charset for file '{}'. Using default charset.", inputFile);
        charset = defaultEncoding;
      }
      InputStream is = charsetDetector.inputStream();
      inputFile.setCharset(charset);
      Metadata metadata = fileMetadata.readMetadata(is, charset, inputFile.absolutePath(), exclusionsScanner.createCharHandlerFor(inputFile));
      inputFile.setMetadata(metadata);
      inputFile.setStatus(statusDetection.status(moduleKeyWithBranch, inputFile, metadata.hash()));
      LOG.debug("'{}' generated metadata{} with charset '{}'", inputFile, inputFile.type() == Type.TEST ? " as test " : "", charset);
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }
83194
protected void check (File source, String mname, int mline, String fname, int fline)
        throws IOException
    {
        if (mline == -1 && fline != -1) {
            throw new IOException(
                "Found " + fname + " marker (at line " + (fline+1) + ") but no " + mname +
                " marker in '" + source + "'.");
        }
    }
1065311
private static boolean encodeFileToFile(String infile, String outfile)
	{
		boolean success = false;
		java.io.InputStream in = null;
		java.io.OutputStream out = null;
		try
		{
			in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
			out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
			byte[] buffer = new byte[65536]; // 64K
			int read = -1;
			while ((read = in.read(buffer)) >= 0)
			{
				out.write(buffer, 0, read);
			} // end while: through file
			success = true;
		}
		catch (java.io.IOException exc)
		{
		}
		finally
		{
			try
			{
				in.close();
			}
			catch (Exception exc)
			{
			}
			try
			{
				out.close();
			}
			catch (Exception exc)
			{
			}
		} // end finally

		return success;
	}
1132263
public boolean valueExists(String name) {
        IntByReference pType, lpcbData;
        byte[] lpData = new byte[1];

        pType = new IntByReference();
        lpcbData = new IntByReference();

        OUTER:
        while(true) {
            int r = Advapi32.INSTANCE.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData);
            switch(r) {
            case WINERROR.ERROR_MORE_DATA:
                lpData = new byte[lpcbData.getValue()];
                continue OUTER;
            case WINERROR.ERROR_FILE_NOT_FOUND:
                return false;
            case WINERROR.ERROR_SUCCESS:
                return true;
            default:
                throw new JnaException(r);
            }
        }
    }
18811
public static boolean containsEntry(File zip, String name) {
    ZipFile zf = null;
    try {
      zf = new ZipFile(zip);
      return zf.getEntry(name) != null;
    }
    catch (IOException e) {
      throw ZipExceptionUtil.rethrow(e);
    }
    finally {
      closeQuietly(zf);
    }
  }
1276310
public static boolean isValid(final String name) {
        if (name == null) {
            return true;
        }
        for (final FileOrder fo : INSTANCES) {
            if (fo.name.equals(name)) {
                return true;
            }
        }
        return false;
    }
1210668
private void validateSchemaWithFilePath(File schemaSourceFile, DataSchema schema)
  {
    if (schemaSourceFile != null && schemaSourceFile.isFile() && schema instanceof NamedDataSchema)
    {
      final NamedDataSchema namedDataSchema = (NamedDataSchema) schema;
      final String namespace = namedDataSchema.getNamespace();

      if (!FileUtil.removeFileExtension(schemaSourceFile.getName()).equalsIgnoreCase(namedDataSchema.getName()))
      {
        throw new IllegalArgumentException(namedDataSchema.getFullName() + " has name that does not match filename '" +
            schemaSourceFile.getAbsolutePath() + "'");
      }

      final String directory = schemaSourceFile.getParentFile().getAbsolutePath();
      if (!directory.endsWith(namespace.replace('.', File.separatorChar)))
      {
        throw new IllegalArgumentException(namedDataSchema.getFullName() + " has namespace that does not match " +
            "file path '" + schemaSourceFile.getAbsolutePath() + "'");
      }
    }
  }
57432
public static void encodeFileToFile(String infile, String outfile) throws IOException {
		String encoded = Base64.encodeFromFile(infile);
		java.io.OutputStream out = null;
		try {
			out = new java.io.BufferedOutputStream(new FileOutputStream(outfile));
			out.write(encoded.getBytes("US-ASCII")); // Strict, 7-bit output.
		} catch (IOException e) {
			throw e; // Catch and release to execute finally{}
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (Exception ex) {
			}
		}
	}
934146
@SuppressWarnings("resource")
    public void read(byte[] keepassFile) throws IOException {
        SafeInputStream inputStream = new SafeInputStream(new BufferedInputStream(new ByteArrayInputStream(keepassFile)));
        inputStream.skipSafe(VERSION_SIGNATURE_LENGTH); // skip version
        
        if(fileFormatVersion == 0) {
            throw new UnsupportedOperationException("File format version not set! Make sure to call checkVersionSupport before ");
        }
        
        while (true) {
            try {
                int fieldId = inputStream.read();
                
                byte[] fieldLength;
                if(fileFormatVersion < DATABASE_V4_FILE_VERSION_INT) {
                    fieldLength = new byte[2];
                }
                else {
                    fieldLength = new byte[4];
                }
                
                inputStream.readSafe(fieldLength);

                ByteBuffer fieldLengthBuffer = ByteBuffer.wrap(fieldLength);
                fieldLengthBuffer.order(ByteOrder.LITTLE_ENDIAN);
                int fieldLengthInt = ByteUtils.toUnsignedInt(fieldLengthBuffer.getShort());

                if (fieldLengthInt > 0) {
                    byte[] data = new byte[fieldLengthInt];
                    inputStream.readSafe(data);
                    setValue(fieldId, data);
                }

                if (fieldId == 0) {
                    break;
                }
            } catch (IOException e) {
                throw new KeePassHeaderUnreadableException("Could not read header input", e);
            }
        }
    }