tikhomirov@295: /* tikhomirov@531: * Copyright (c) 2011-2013 TMate Software Ltd tikhomirov@295: * tikhomirov@295: * This program is free software; you can redistribute it and/or modify tikhomirov@295: * it under the terms of the GNU General Public License as published by tikhomirov@295: * the Free Software Foundation; version 2 of the License. tikhomirov@295: * tikhomirov@295: * This program is distributed in the hope that it will be useful, tikhomirov@295: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@295: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@295: * GNU General Public License for more details. tikhomirov@295: * tikhomirov@295: * For information on how to redistribute this software under tikhomirov@295: * the terms of a license other than GNU General Public License tikhomirov@295: * contact TMate Software at support@hg4j.com tikhomirov@295: */ tikhomirov@423: package org.tmatesoft.hg.repo; tikhomirov@295: tikhomirov@295: import java.io.File; tikhomirov@295: import java.io.IOException; tikhomirov@295: tikhomirov@628: import org.tmatesoft.hg.util.Path; tikhomirov@628: tikhomirov@295: /** tikhomirov@295: * Thrown when there are troubles working with local file. Most likely (but not necessarily) wraps IOException. Might be tikhomirov@295: * perceived as specialized IOException with optional File and other repository information. tikhomirov@295: * tikhomirov@295: * Hg4J tries to minimize chances for IOException to occur (i.e. {@link File#canRead()} is checked before attempt to tikhomirov@295: * read a file that might not exist, and doesn't use this exception to wrap each and any {@link IOException} source (e.g. tikhomirov@295: * #close() calls are unlikely to yield it), hence it is likely to address real cases when I/O error occurs. tikhomirov@295: * tikhomirov@295: * On the other hand, when a file is supposed to exist and be readable, this exception might get thrown as well to indicate tikhomirov@295: * that's not true. tikhomirov@295: * tikhomirov@295: * @author Artem Tikhomirov tikhomirov@295: * @author TMate Software Ltd. tikhomirov@295: */ tikhomirov@295: @SuppressWarnings("serial") tikhomirov@423: public class HgInvalidFileException extends HgRuntimeException { tikhomirov@423: // IMPLEMENTATION NOTE: Once needed, there might be intermediate e.g. HgDataStreamException tikhomirov@423: // (between HgInvalidFileException and HgRuntimeException) to root data access exceptions tikhomirov@423: // that do not originate from local files but e.g. a connection tikhomirov@295: tikhomirov@295: public HgInvalidFileException(String message, Throwable th) { tikhomirov@295: super(message, th); tikhomirov@295: } tikhomirov@295: tikhomirov@531: /** tikhomirov@531: * tikhomirov@531: * @param message description of the trouble, may (although should not) be null tikhomirov@531: * @param th cause, optional tikhomirov@531: * @param file where the trouble is, may be null, can be altered later with {@link #setFile(File)} tikhomirov@531: */ tikhomirov@295: public HgInvalidFileException(String message, Throwable th, File file) { tikhomirov@295: super(message, th); tikhomirov@423: details.setFile(file); // allows null tikhomirov@295: } tikhomirov@295: tikhomirov@295: public HgInvalidFileException setFile(File file) { tikhomirov@394: assert file != null; // doesn't allow null not to clear file accidentally tikhomirov@423: details.setFile(file); tikhomirov@295: return this; tikhomirov@295: } tikhomirov@628: tikhomirov@628: @Override tikhomirov@628: public HgInvalidFileException setFileName(Path name) { tikhomirov@628: super.setFileName(name); tikhomirov@628: return this; tikhomirov@628: } tikhomirov@295: tikhomirov@295: /** tikhomirov@295: * @return file object that causes troubles, or null if specific file is unknown tikhomirov@295: */ tikhomirov@295: public File getFile() { tikhomirov@423: return details.getFile(); tikhomirov@391: } tikhomirov@295: }