反序列化对象

@param file 对象文件

@return 反序列化后的对象

@throws IOException 异常
@throws ClassNotFoundException 异常
@since 1.0.8
550168
public static Object deserialize(String file) throws IOException, ClassNotFoundException {
        Object object;
        try (FileInputStream fileIn = new FileInputStream(file); ObjectInputStream in = new ObjectInputStream(fileIn)) {
            object = in.readObject();
        }
        return object;
    }
531806
@Nonnull
    public static String readFile(@Nonnull File file, @Nonnull Charset charset) throws IOException {
        if (file == null)
            throw new NullPointerException("Given 'file' can not be null");
        if (!file.exists())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " does not exist");
        if (file.isDirectory())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " can NOT be a directory");

        InputStream in = new BufferedInputStream(new FileInputStream(file));
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        copy(in, bos);
        return new String(bos.toByteArray(), charset);

    }
112082
private static boolean isValidJavaClassFile(String file) {
        if (!file.endsWith(".class")) return false;
        String clazzName = file.substring(0, file.length() - ".class".length());
        return isValidClassName(clazzName);
    }
614099
public static String readTextFile(File file) throws IOException
    {
        //create reader to file (with default encoding)
        InputStream inputStream=new FileInputStream(file);
        Reader reader=IOHelper.createReader(inputStream,null);

        //read text
        String text=IOHelper.readTextStream(reader);
        
        return text;
    }
374081
public static String file(File file) throws IOException {
        FileInputStream fi = null;
        try {
            fi = new FileInputStream(file);
            return stream(fi, file.length());
        } finally {
            if (fi != null) {
                try {
                    fi.close();
                } catch (Throwable t) {
                }
            }
        }

    }
845513
public static String readFile(InputStream file) {
        try (BufferedInputStream stream = new BufferedInputStream(file)) {
            byte[] buff = new byte[1024];
            StringBuilder builder = new StringBuilder();
            int read;
            while ((read = stream.read(buff)) != -1) {
                builder.append(new String(buff, 0, read, StandardCharsets.UTF_8));
            }
            return builder.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
1088842
public static FileInputStream getFileInputStreamPrivileged(final File file) throws FileNotFoundException {
        final AtomicReference<FileNotFoundException> exceptionRef = new AtomicReference<FileNotFoundException>();
        FileInputStream fis = AccessController.doPrivileged(new PrivilegedAction<FileInputStream>() {
            @Override
            public FileInputStream run() {
                try {
                    return new FileInputStream(file);
                } catch (FileNotFoundException e) {
                    exceptionRef.set(e);
                    return null;
                }
            }
        });

        if (exceptionRef.get() != null)
            throw exceptionRef.get();

        return fis;
    }
815907
public static Dependencies load(final File file) {
        Utils4J.checkNotNull("file", file);
        Utils4J.checkValidFile(file);
        try {
            final InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
            try {
                return load(inputStream);
            } finally {
                inputStream.close();
            }
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
    }
915779
public static String fileAsString(File file) {
    try {
      return inputStreamAsString(new FileInputStream(file));
    } catch(FileNotFoundException e) {
      throw LOG.fileNotFoundException(file.getAbsolutePath(), e);
    }
  }
584766
public byte[] transform(String className, File file) throws IOException, IllegalClassFormatException {
		try {
			return transform(className, new FileInputStream(file));
			
		} catch (FileNotFoundException e){
			throw new RuntimeException(e);
		}
	}
370771
public ClassFinder add(File file) {
    log.info("Adding file to look into: " + file.getAbsolutePath());

    if (fileCanContainClasses(file)) {
      String absPath = file.getAbsolutePath();
      if (placesToSearch.get(absPath) == null) {
        placesToSearch.put(absPath, file);
        for (AdditionalResourceLoader resourceLoader : resourceLoaders) {
          if (resourceLoader.canLoadAdditional(file)) resourceLoader.loadAdditional(file, this);
        }
      }
    } else {
      log.info("The given path '" + file.getAbsolutePath() + "' cannot contain classes!");
    }

    return this;
  }
1057701
public static String readFile( File file ) throws IOException {
        if (!file.exists()) {
            throw new FileNotFoundException("The required projection file is not available: " + file.getAbsolutePath());
        }
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            StringBuilder sb = new StringBuilder(200);
            String line;
            while( (line = br.readLine()) != null ) {
                sb.append(line);
                sb.append("\n"); //$NON-NLS-1$
            }
            return sb.toString();
        }
    }
71405
public SourceFile getSourceFile(File file) throws IOException
	{
		SourceFile source = sourceFiles.get(file);

		if (source == null)
		{
			source = new SourceFile(file);
			sourceFiles.put(file, source);
		}

		return source;
	}
1269911
public static Properties load(File file) throws IOException {
		FileInputStream input = new FileInputStream(file);
		Properties properties = null;
		try {
			properties = load(input);
		} finally {
			IOUtils.close(input);
		}
		return properties;
	}
59060
public Class parseClass(File file) throws CompilationFailedException, IOException {
        return parseClass(new GroovyCodeSource(file, config.getSourceEncoding()));
    }
519048
public static Properties fromFile(
    final File file)
    throws IOException
  {
    Objects.requireNonNull(file, "File");

    try (InputStream stream = Files.newInputStream(file.toPath())) {
      final Properties p = new Properties();
      p.load(stream);
      return p;
    }
  }
435182
public static byte[] getBytes(File file) throws IOException {
		InputStream in = new FileInputStream(file);
		int fileSize = (int) file.length();

		if (fileSize > Integer.MAX_VALUE) {
			in.close();
			throw new IOException("File size to large: " + fileSize + " > " + Integer.MAX_VALUE);
		}

		byte[] bytes = new byte[fileSize];

		// Read in the bytes
		int offset = 0;
		int numRead = 0;
		while (offset < bytes.length && (numRead = in.read(bytes, offset, bytes.length-offset)) >= 0) {
			offset += numRead;
		}

		// Ensure all the bytes have been read in
		if (offset < bytes.length) {
			in.close();
			throw new IOException("Could not completely read file " + file.getName());
		}

		in.close();

		return bytes;
	}