Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added dep/commons-vfs-2.0-SNAPSHOT.jar
Binary file not shown.
Binary file added dep/gaevfs-0.3-javadoc.jar
Binary file not shown.
Binary file added dep/gaevfs-0.3.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions dep/install-jars-to-mvn.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
call mvn install:install-file -Dfile=commons-vfs-2.0-SNAPSHOT.jar -DgroupId=org.apache.commons -DartifactId=commons-vfs -Dversion=2.0-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
call mvn install:install-file -Dfile=gaevfs-0.3.jar -DgroupId=com.newatlanta.commons -DartifactId=gaevfs -Dversion=0.3 -Dpackaging=jar -DgeneratePom=true
call mvn install:install-file -Dfile=sfntly-0.0.1-SNAPSHOT.jar -DgroupId=com.github.sfntly -DartifactId=sfntly -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
Binary file added dep/sfntly-0.0.1-SNAPSHOT.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
<artifactId>sfntly</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.newatlanta.commons</groupId>
<artifactId>gaevfs</artifactId>
<version>0.3</version>
</dependency>
</dependencies>
<scm>
<url>https://github.com/pascalleclercq/appengine-awt</url>
Expand Down
19 changes: 4 additions & 15 deletions src/main/java/com/google/code/appengine/imageio/ImageIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,20 @@
import org.apache.harmony.luni.util.NotImplementedException;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Arrays;
import java.util.List;
import java.net.URL;
import org.apache.harmony.x.imageio.internal.nls.Messages;
import org.apache.sanselan.ImageReadException;
import org.apache.sanselan.Sanselan;
import org.apache.sanselan.common.byteSources.ByteSource;
import org.apache.sanselan.common.byteSources.ByteSourceInputStream;
import org.apache.sanselan.formats.gif.GifImageParser;
import org.apache.sanselan.formats.png.PngImageParser;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.Imaging;

import com.google.code.appengine.awt.image.BufferedImage;
import com.google.code.appengine.awt.image.RenderedImage;
import com.google.code.appengine.imageio.ImageReader;
import com.google.code.appengine.imageio.ImageTranscoder;
import com.google.code.appengine.imageio.ImageTypeSpecifier;
import com.google.code.appengine.imageio.ImageWriter;
import com.google.code.appengine.imageio.spi.*;
import com.google.code.appengine.imageio.stream.ImageInputStream;
import com.google.code.appengine.imageio.stream.ImageOutputStream;
Expand Down Expand Up @@ -338,7 +327,7 @@ else if(name.endsWith(".gif")) {
}*/

try {
return Sanselan.getBufferedImage(input);
return Imaging.getBufferedImage(input);
} catch (ImageReadException e) {
// TODO Auto-generated catch block
throw new IOException(e);
Expand All @@ -354,7 +343,7 @@ public static BufferedImage read(InputStream input) throws IOException {
}

try {
return Sanselan.getBufferedImage(input);
return Imaging.getBufferedImage(input);
} catch (ImageReadException e) {
// TODO Auto-generated catch block
throw new IOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@

package com.google.code.appengine.imageio.stream;

import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;


import com.newatlanta.commons.vfs.provider.gae.GaeFileObject;
import com.newatlanta.commons.vfs.provider.gae.GaeFileSystemManager;
import com.newatlanta.commons.vfs.provider.gae.GaeRandomAccessContent;
import com.newatlanta.commons.vfs.provider.gae.GaeVFS;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.util.RandomAccessMode;
import org.apache.harmony.x.imageio.internal.nls.Messages;

import com.google.code.appengine.imageio.stream.FileCacheImageOutputStream;
import com.google.code.appengine.imageio.stream.ImageInputStreamImpl;

public class FileCacheImageInputStream extends ImageInputStreamImpl {
private InputStream is;
private File file;
private RandomAccessFile raf;
private GaeFileObject file;
private GaeRandomAccessContent rac;


public FileCacheImageInputStream(InputStream stream, File cacheDir) throws IOException {
Expand All @@ -38,55 +44,65 @@ public FileCacheImageInputStream(InputStream stream, File cacheDir) throws IOExc
}
is = stream;

if (cacheDir == null || cacheDir.isDirectory()) {
file = File.createTempFile(FileCacheImageOutputStream.IIO_TEMP_FILE_PREFIX, null, cacheDir);
file.deleteOnExit();
// Retrieve the file system manager
GaeFileSystemManager fsManager = GaeVFS.getManager();

// Convert cacheDir to a FileObject
GaeFileObject cacheDirObj = (cacheDir == null) ? null :
(GaeFileObject)fsManager.resolveFile(cacheDir.getPath());

// if cache dir is null, or if it is a directory
if (cacheDirObj == null || cacheDirObj.getType() == FileType.FOLDER) {

// original code:
file = FileObjectUtils.createTempFileObject(fsManager,
FileCacheImageOutputStream.IIO_TEMP_FILE_PREFIX, null, cacheDirObj);
} else {
throw new IllegalArgumentException(Messages.getString("imageio.0B"));
}

raf = new RandomAccessFile(file, "rw");
rac = new GaeRandomAccessContent(file, RandomAccessMode.READWRITE);
}

@Override
public int read() throws IOException {
bitOffset = 0;

if (streamPos >= raf.length()) {
if (streamPos >= rac.length()) {
int b = is.read();

if (b < 0) {
return -1;
}

raf.seek(streamPos++);
raf.write(b);
rac.seek(streamPos++);
rac.write(b);
return b;
}

raf.seek(streamPos++);
return raf.read();
rac.seek(streamPos++);
return rac.read();
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
bitOffset = 0;

if (streamPos >= raf.length()) {
if (streamPos >= rac.length()) {
int nBytes = is.read(b, off, len);

if (nBytes < 0) {
return -1;
}

raf.seek(streamPos);
raf.write(b, off, nBytes);
rac.seek(streamPos);
rac.write(b, off, nBytes);
streamPos += nBytes;
return nBytes;
}

raf.seek(streamPos);
int nBytes = raf.read(b, off, len);
rac.seek(streamPos);
int nBytes = rac.read(b, off, len);
streamPos += nBytes;
return nBytes;
}
Expand All @@ -109,7 +125,7 @@ public boolean isCachedMemory() {
@Override
public void close() throws IOException {
super.close();
raf.close();
rac.close();
file.delete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package com.google.code.appengine.imageio.stream;

import com.newatlanta.commons.vfs.provider.gae.GaeFileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileType;

import java.math.BigInteger;
import java.security.SecureRandom;

/**
* Utility class for GaeFileObject. Contains methods for things such as creating a temporary file object.
*/
public class FileObjectUtils {
private FileObjectUtils(){}

public final static class RandStringGenerator {
private static SecureRandom random = new SecureRandom();

public static String nextString() {
return new BigInteger(130, random).toString(32);
}
}

public static GaeFileObject createTempFileObject(FileSystemManager fsManager, String prefix, String suffix, GaeFileObject directory) throws FileSystemException {
if (suffix == null) suffix = ".tmp";
GaeFileObject file;

if (directory == null || (directory.getType()== FileType.FOLDER)) {
String name = RandStringGenerator.nextString();
String filename = prefix + name + suffix;
file = (GaeFileObject)fsManager.resolveFile(filename);
while (file.exists()) {
name = RandStringGenerator.nextString();
filename = prefix + name + suffix;
file = (GaeFileObject)fsManager.resolveFile(filename);
}
// guaranteed file doesn't exist at this point
file.createFile();
} else {
throw new IllegalArgumentException("directory must be a directory!");
}

return file;
}
}
Loading