All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.core.internal.localstore.SafeFileInputStream Maven / Gradle / Ivy

Go to download

AspectJ tools most notably contains the AspectJ compiler (AJC). AJC applies aspects to Java classes during compilation, fully replacing Javac for plain Java classes and also compiling native AspectJ or annotation-based @AspectJ syntax. Furthermore, AJC can weave aspects into existing class files in a post-compile binary weaving step. This library is a superset of AspectJ weaver and hence also of AspectJ runtime.

There is a newer version: 1.9.22.1
Show newest version
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.internal.localstore;

import java.io.*;

/**
 * Given a target and a temporary locations, it tries to read the contents
 * from the target. If a file does not exist at the target location, it tries
 * to read the contents from the temporary location.
 *
 * @see SafeFileOutputStream
 */
public class SafeFileInputStream extends FilterInputStream {
	protected static final String EXTENSION = ".bak"; //$NON-NLS-1$
	private static final int DEFAUT_BUFFER_SIZE = 2048;

	public SafeFileInputStream(File file) throws IOException {
		this(file.getAbsolutePath(), null);
	}

	/**
	 * If targetPath is null, the file will be created in the default-temporary directory.
	 */
	public SafeFileInputStream(String targetPath, String tempPath) throws IOException {
		super(getInputStream(targetPath, tempPath, DEFAUT_BUFFER_SIZE));
	}

	/**
	 * If targetPath is null, the file will be created in the default-temporary directory.
	 */
	public SafeFileInputStream(String targetPath, String tempPath, int bufferSize) throws IOException {
		super(getInputStream(targetPath, tempPath, bufferSize));
	}

	private static InputStream getInputStream(String targetPath, String tempPath, int bufferSize) throws IOException {
		File target = new File(targetPath);
		if (!target.exists()) {
			if (tempPath == null)
				tempPath = target.getAbsolutePath() + EXTENSION;
			target = new File(tempPath);
		}
		return new BufferedInputStream(new FileInputStream(target), bufferSize);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy