本文整理汇总了Java中org.apache.commons.vfs.FileContent类的典型用法代码示例。如果您正苦于以下问题:Java FileContent类的具体用法?Java FileContent怎么用?Java FileContent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileContent类属于org.apache.commons.vfs包,在下文中一共展示了FileContent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: loadResource
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
/** Load the resource specified by the given path. If monitor is true then
the ResourceLoader implementation will monitor the resource and call the
ResourceRecipient each time the resource is modified.
@param path The path
@param handler The ResourceRecipient callback
@param monitor True to monitor the resource
@throws ResourceException
*/
public void loadResource(String path, ResourceRecipient handler,
boolean monitor) throws ResourceException{
InputStream in = null;
try{
FileSystemManager fsManager = getFileSystemManager();
log.debug("Resource path: " + path);
FileObject file = fsManager.resolveFile(path);
if(!file.exists()){
throw new FileNotFoundException("File not found: " + file);
}
FileContent content = file.getContent();
in = content.getInputStream();
handler.load(in);
if(monitor){
ResourceVFSMonitor resourceMonitor = new ResourceVFSMonitor(
file, getDelay(), handler);
getMonitors().add(resourceMonitor);
resourceMonitor.startMonitor();
}
} catch(Exception e){
e.printStackTrace();
throw new ResourceException(e);
} finally {
IOUtilities.close(in);
}
}
开发者ID:florinpatrascu,项目名称:jpublish,代码行数:39,代码来源:VFSResourceLoader.java
示例2: readData
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
/**
* Read the data from the given file into a byte array and return
* the array.
*
* @param file The file
* @return The byte array
* @throws IOException
*/
public static byte[] readData(FileObject file) throws IOException {
BufferedInputStream in = null;
ByteArrayOutputStream out = null;
try {
FileContent content = file.getContent();
in = new BufferedInputStream(content.getInputStream());
out = new ByteArrayOutputStream();
int c = -1;
while ((c = in.read()) != -1) {
out.write(c);
}
return out.toByteArray();
} finally {
IOUtilities.close(in);
IOUtilities.close(out);
}
}
开发者ID:florinpatrascu,项目名称:jpublish,代码行数:30,代码来源:IOUtilities.java
示例3: create
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
public FileContentInfo create(FileContent fileContent) throws FileSystemException
{
WebdavFileObject file = (WebdavFileObject) (FileObjectUtils
.getAbstractFileObject(fileContent.getFile()));
String contentType = null;
String contentEncoding = null;
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DavPropertyName.GETCONTENTTYPE);
DavPropertySet propertySet = file.getProperties((URLFileName) file.getName(), nameSet, true);
DavProperty property = propertySet.get(DavPropertyName.GETCONTENTTYPE);
if (property != null)
{
contentType = (String) property.getValue();
}
property = propertySet.get(WebdavFileObject.RESPONSE_CHARSET);
if (property != null)
{
contentEncoding = (String) property.getValue();
}
return new DefaultFileContentInfo(contentType, contentEncoding);
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:26,代码来源:WebdavFileContentInfoFactory.java
示例4: getScheme
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
/**
* Finds the provider to use to create a filesystem from a given file.
*/
public String getScheme(final FileObject file) throws FileSystemException
{
// Check the file's mime type for a match
final FileContent content = file.getContent();
// final String mimeType = (String) content.getAttribute("content-type");
final String mimeType = content.getContentInfo().getContentType();
if (mimeType != null)
{
return (String) mimeTypeMap.get(mimeType);
}
// Check the file's extension for a match
final String extension = file.getName().getExtension();
return (String) extensionMap.get(extension);
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:19,代码来源:FileTypeMap.java
示例5: getContent
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
/**
* <p>
* byte형으로 파일의 내용을 읽어온다.
* <p>
* @param file
* <code>FileObject</code>
* @return 파일 내용
* @throws IOException
*/
public static byte[] getContent(final FileObject file) throws IOException {
final FileContent content = file.getContent();
final int size = (int) content.getSize();
final byte[] buf = new byte[size];
final InputStream in = content.getInputStream();
try {
int read = 0;
for (int pos = 0; pos < size && read >= 0; pos += read) {
read = in.read(buf, pos, size - pos);
}
} finally {
in.close();
}
return buf;
}
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:27,代码来源:EgovFileUtil.java
示例6: writeData
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
/**
* Write the byte array to the given file.
*
* @param file The file to write to
* @param data The data array
* @throws IOException
*/
public static void writeData(FileObject file, byte[] data)
throws IOException {
OutputStream out = null;
try {
FileContent content = file.getContent();
out = content.getOutputStream();
out.write(data);
} finally {
close(out);
}
}
开发者ID:florinpatrascu,项目名称:jpublish,代码行数:20,代码来源:IOUtilities.java
示例7: setPropertyValue
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
protected boolean setPropertyValue(Element root, Element propertyEl) {
LogFactory.getLog(getClass()).debug(String.format("[%s].set('%s')", object.getName(), propertyEl.asXML()));
if (!ALL_PROPERTIES.contains(propertyEl.getName())) {
final String nameSpace = propertyEl.getNamespaceURI();
final String attributeName = getFQName(nameSpace, propertyEl.getName());
try {
FileContent objectContent = object.getContent();
final String command = propertyEl.getParent().getParent().getName();
if (TAG_PROP_SET.equals(command)) {
StringWriter propertyValueWriter = new StringWriter();
propertyEl.write(propertyValueWriter);
propertyValueWriter.close();
objectContent.setAttribute(attributeName, propertyValueWriter.getBuffer().toString());
} else if (TAG_PROP_REMOVE.equals(command)) {
objectContent.setAttribute(attributeName, null);
}
root.addElement(propertyEl.getQName());
return true;
} catch (IOException e) {
LogFactory.getLog(getClass()).error(String.format("can't store attribute property '%s' = '%s'",
attributeName,
propertyEl.asXML()), e);
}
}
return false;
}
开发者ID:thinkberg,项目名称:moxo,代码行数:28,代码来源:DavResource.java
示例8: getOutputStream
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
public static OutputStream getOutputStream(FileObject fileObject, boolean append) throws IOException
{
FileObject parent = fileObject.getParent();
if (parent!=null)
{
if (!parent.exists())
{
throw new IOException(Messages.getString("KettleVFS.Exception.ParentDirectoryDoesNotExist", getFilename(parent)));
}
}
try
{
fileObject.createFile();
FileContent content = fileObject.getContent();
return content.getOutputStream(append);
}
catch(FileSystemException e)
{
// Perhaps if it's a local file, we can retry using the standard
// File object. This is because on Windows there is a bug in VFS.
//
if (fileObject instanceof LocalFile)
{
try
{
String filename = getFilename(fileObject);
return new FileOutputStream(new File(filename), append);
}
catch(Exception e2)
{
throw e; // throw the original exception: hide the retry.
}
}
else
{
throw e;
}
}
}
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:40,代码来源:KettleVFS.java
示例9: getOutputStream
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
public static OutputStream getOutputStream(FileObject fileObject, boolean append) throws IOException
{
FileObject parent = fileObject.getParent();
if (parent!=null)
{
if (!parent.exists())
{
throw new IOException(BaseMessages.getString(PKG, "KettleVFS.Exception.ParentDirectoryDoesNotExist", getFilename(parent)));
}
}
try
{
fileObject.createFile();
FileContent content = fileObject.getContent();
return content.getOutputStream(append);
}
catch(FileSystemException e)
{
// Perhaps if it's a local file, we can retry using the standard
// File object. This is because on Windows there is a bug in VFS.
//
if (fileObject instanceof LocalFile)
{
try
{
String filename = getFilename(fileObject);
return new FileOutputStream(new File(filename), append);
}
catch(Exception e2)
{
throw e; // throw the original exception: hide the retry.
}
}
else
{
throw e;
}
}
}
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:40,代码来源:KettleVFS.java
示例10: JarURLConnectionImpl
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
public JarURLConnectionImpl(JarFileObject file, FileContent content)
throws MalformedURLException, FileSystemException
{
//This is because JarURLConnection SUCKS!!
super(new URL(HACK_URL));
this.url = file.getURL();
this.content = content;
this.parentURL = file.getURL();
this.entryName = file.getName().getPath();
this.file = file;
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:13,代码来源:JarURLConnectionImpl.java
示例11: create
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
public FileContentInfo create(FileContent fileContent) throws FileSystemException
{
HttpFileObject httpFile = (HttpFileObject) (FileObjectUtils
.getAbstractFileObject(fileContent.getFile()));
String contentType = null;
String contentEncoding = null;
Header header = httpFile.getHeadMethod().getResponseHeader("content-type");
if (header != null)
{
HeaderElement[] element;
try
{
element = header.getValues();
}
catch (HttpException e)
{
throw new FileSystemException(e);
}
if (element != null && element.length > 0)
{
contentType = element[0].getName();
}
}
contentEncoding = httpFile.getHeadMethod().getResponseCharSet();
return new DefaultFileContentInfo(contentType, contentEncoding);
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:31,代码来源:HttpFileContentInfoFactory.java
示例12: getContent
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
/**
* Returns the file's content.
* @return the FileContent for this FileObject.
* @throws FileSystemException if an error occurs.
*/
public FileContent getContent() throws FileSystemException
{
synchronized (fs)
{
attach();
if (content == null)
{
content = doCreateFileContent();
}
return content;
}
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:18,代码来源:AbstractFileObject.java
示例13: create
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
public FileContentInfo create(FileContent fileContent)
{
String contentType = null;
String name = fileContent.getFile().getName().getBaseName();
if (name != null)
{
FileNameMap fileNameMap = URLConnection.getFileNameMap();
contentType = fileNameMap.getContentTypeFor(name);
}
return new DefaultFileContentInfo(contentType, null);
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:14,代码来源:FileContentInfoFilenameFactory.java
示例14: getContent
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
public FileContent getContent() throws FileSystemException
{
synchronized (this)
{
return super.getContent();
}
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:8,代码来源:SynchronizedFileObject.java
示例15: assertSameContent
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
/**
* Asserts that the content of a file is the same as expected. Checks the
* length reported by getSize() is correct, then reads the content as
* a byte stream and compares the result with the expected content.
* Assumes files are encoded using UTF-8.
*/
protected void assertSameContent(final String expected,
final FileObject file)
throws Exception
{
// Check the file exists, and is a file
assertTrue(file.exists());
assertSame(FileType.FILE, file.getType());
// Get file content as a binary stream
final byte[] expectedBin = expected.getBytes("utf-8");
// Check lengths
final FileContent content = file.getContent();
assertEquals("same content length", expectedBin.length, content.getSize());
// Read content into byte array
final InputStream instr = content.getInputStream();
final ByteArrayOutputStream outstr;
try
{
outstr = new ByteArrayOutputStream(expectedBin.length);
final byte[] buffer = new byte[256];
int nread = 0;
while (nread >= 0)
{
outstr.write(buffer, 0, nread);
nread = instr.read(buffer);
}
}
finally
{
instr.close();
}
// Compare
assertTrue("same binary content", Arrays.equals(expectedBin, outstr.toByteArray()));
}
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:44,代码来源:AbstractProviderTestCase.java
示例16: testReadOnlyGetContentInputStream
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
@Test
public void testReadOnlyGetContentInputStream() throws IOException {
createRealFile();
final FileContent content = readOnlyFile.getContent();
try {
content.getInputStream().close();
} finally {
content.close();
}
}
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:12,代码来源:AbstractLimitingFileObjectTest.java
示例17: testReadOnlyGetContentOutputStream
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
@Test
public void testReadOnlyGetContentOutputStream() throws IOException {
createRealFile();
final FileContent content = readOnlyFile.getContent();
try {
content.getOutputStream();
fail("Expected exception");
} catch (FileSystemException x) {
} finally {
content.close();
}
}
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:14,代码来源:AbstractLimitingFileObjectTest.java
示例18: testReadOnlyGetContentRandomInputStream
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
@Test
public void testReadOnlyGetContentRandomInputStream() throws IOException {
createRealFile();
final FileContent content = readOnlyFile.getContent();
try {
content.getRandomAccessContent(RandomAccessMode.READ).close();
} finally {
content.close();
}
}
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:12,代码来源:AbstractLimitingFileObjectTest.java
示例19: testReadOnlyGetContentRandomOutputStream
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
@Test
public void testReadOnlyGetContentRandomOutputStream() throws IOException {
createRealFile();
final FileContent content = readOnlyFile.getContent();
try {
content.getRandomAccessContent(RandomAccessMode.READWRITE).close();
fail("Expected exception");
} catch (FileSystemException x) {
} finally {
content.close();
}
}
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:14,代码来源:AbstractLimitingFileObjectTest.java
示例20: testReadWriteGetContentInputStream
import org.apache.commons.vfs.FileContent; //导入依赖的package包/类
@Test
public void testReadWriteGetContentInputStream() throws IOException {
createRealFile();
final FileContent content = readWriteFile.getContent();
try {
content.getInputStream().close();
} finally {
content.close();
}
}
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:12,代码来源:AbstractLimitingFileObjectTest.java
注:本文中的org.apache.commons.vfs.FileContent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论