blob: bba98ab043efa8a06e68172c969665cc290f3b4c [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 Borland Software Corporation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Borland Software Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.m2m.internal.qvt.oml.common.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class IOFile extends IOResource implements CFile {
public IOFile(String file) {
this(new File(file));
}
public IOFile(File file) {
super(file);
if(file.exists() && !file.isFile()) {
throw new IllegalArgumentException("Not a file: " + file); //$NON-NLS-1$
}
myUnitName = myFile.getName();
int dot = myUnitName.lastIndexOf('.');
if(dot != -1) {
myUnitName = myUnitName.substring(0, dot);
}
}
@Override
public boolean equals(Object other) {
return other instanceof IOFile &&
((IOFile)other).myFile.equals(myFile);
}
@Override
public int hashCode() {
return myFile.hashCode();
}
public InputStream getContents() throws IOException {
return new FileInputStream(myFile);
}
public String getUnitName() {
return myUnitName;
}
public long getTimeStamp() {
return myFile.lastModified();
}
public void create(InputStream contents) throws IOException {
FileUtil.setContents(myFile, contents);
}
public void setContents(InputStream contents) throws IOException {
FileUtil.setContents(myFile, contents);
}
public String getCharset() throws IOException {
return getWorkspaceCharset();
}
private String myUnitName;
}