Skip to content

Commit

Permalink
Moved getContents() to Resource interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Oct 17, 2013
1 parent eca9bbb commit e6baad1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,34 +206,6 @@ private boolean _deleteRecursive(final File file, final boolean collect)
return getFileOperations().deleteFile(file);
}

@Override
public String getContents()
{
InputStream stream = getResourceInputStream();
try
{
return Streams.toString(stream);
}
finally
{
Streams.closeQuietly(stream);
}
}

@Override
public String getContents(Charset charset)
{
InputStream stream = getResourceInputStream();
try
{
return Streams.toString(stream, charset);
}
finally
{
Streams.closeQuietly(stream);
}
}

@Override
public T setContents(String data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
*/
package org.jboss.forge.addon.resource;

import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.jboss.forge.addon.facets.AbstractFaceted;
import org.jboss.forge.furnace.util.Streams;

/**
* @author Mike Brock <cbrock@redhat.com>
Expand Down Expand Up @@ -95,6 +98,34 @@ public synchronized List<Resource<?>> listResources(final ResourceFilter filter)

return result;
}

@Override
public String getContents()
{
InputStream stream = getResourceInputStream();
try
{
return Streams.toString(stream);
}
finally
{
Streams.closeQuietly(stream);
}
}

@Override
public String getContents(Charset charset)
{
InputStream stream = getResourceInputStream();
try
{
return Streams.toString(stream, charset);
}
finally
{
Streams.closeQuietly(stream);
}
}

@Override
public boolean equals(final Object obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ public interface FileResource<T extends FileResource<T>> extends Resource<File>
*/
public void deleteOnExit();

/**
* Get the entire contents of this {@link FileResource}, returned as a {@link String} using UTF-8 encoding.
*/
public String getContents();

/**
* Get the entire contents of this {@link FileResource}, returned as a {@link String} using the specified encoding.
*/
public String getContents(Charset charset);

/**
* Set the contents of this {@link FileResource} to the given {@link String} using UTF-8 encoding.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.File;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;

import org.jboss.forge.addon.facets.Faceted;
Expand Down Expand Up @@ -99,6 +100,16 @@ public interface Resource<T> extends Faceted<ResourceFacet>
*/
InputStream getResourceInputStream();

/**
* Get the entire contents of this {@link Resource}, returned as a {@link String} using UTF-8 encoding.
*/
public String getContents();

/**
* Get the entire contents of this {@link Resource}, returned as a {@link String} using the specified encoding.
*/
public String getContents(Charset charset);

/**
* Get a child of this resource. Returns <code>null</code> if no child by the given name can be found.
*/
Expand Down

0 comments on commit e6baad1

Please sign in to comment.