dew/src/main/java/org/apidesign/bck2brwsr/dew/MemoryFileObject.java
changeset 1372 cc58b30499e5
parent 1371 fd2d4ca28bd3
child 1373 c4e57ec5f0df
     1.1 --- a/dew/src/main/java/org/apidesign/bck2brwsr/dew/MemoryFileObject.java	Sat Oct 12 09:05:08 2013 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,137 +0,0 @@
     1.4 -/**
     1.5 - * Back 2 Browser Bytecode Translator
     1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, version 2 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. Look for COPYING file in the top folder.
    1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 - */
    1.21 -
    1.22 -package org.apidesign.bck2brwsr.dew;
    1.23 -
    1.24 -import java.io.ByteArrayInputStream;
    1.25 -import java.io.ByteArrayOutputStream;
    1.26 -import java.io.IOException;
    1.27 -import java.io.InputStream;
    1.28 -import java.io.InputStreamReader;
    1.29 -import java.io.OutputStream;
    1.30 -import java.io.OutputStreamWriter;
    1.31 -import java.io.Reader;
    1.32 -import java.io.Writer;
    1.33 -
    1.34 -/**
    1.35 - *
    1.36 - * @author Tomas Zeuzla
    1.37 - */
    1.38 -class MemoryFileObject extends BaseFileObject {
    1.39 -
    1.40 -    private byte[] content;
    1.41 -    private long lastModified;
    1.42 -
    1.43 -    MemoryFileObject (
    1.44 -            String resourceName,
    1.45 -            Kind kind,
    1.46 -            byte[] content) {
    1.47 -        super(resourceName, kind);
    1.48 -        this.content = content;
    1.49 -        this.lastModified = this.content == null ?
    1.50 -            -1 :
    1.51 -            System.currentTimeMillis();
    1.52 -    }
    1.53 -
    1.54 -    MemoryFileObject (
    1.55 -            String resourceName,
    1.56 -            byte[] content) {
    1.57 -        this(resourceName, getKind(resourceName) ,content);
    1.58 -    }
    1.59 -
    1.60 -
    1.61 -    @Override
    1.62 -    public InputStream openInputStream() throws IOException {
    1.63 -        if (content == null) {
    1.64 -            throw new IOException();
    1.65 -        } else {
    1.66 -            return new ByteArrayInputStream(content);
    1.67 -        }
    1.68 -    }
    1.69 -
    1.70 -    @Override
    1.71 -    public OutputStream openOutputStream() throws IOException {
    1.72 -        return new CloseStream();
    1.73 -    }
    1.74 -
    1.75 -    @Override
    1.76 -    public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
    1.77 -        return new InputStreamReader(openInputStream());
    1.78 -    }
    1.79 -
    1.80 -    @Override
    1.81 -    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
    1.82 -        if (content == null) {
    1.83 -            throw new IOException();
    1.84 -        } else {
    1.85 -            return new String(content);
    1.86 -        }
    1.87 -    }
    1.88 -
    1.89 -    @Override
    1.90 -    public Writer openWriter() throws IOException {
    1.91 -        return new OutputStreamWriter(openOutputStream());
    1.92 -    }
    1.93 -
    1.94 -    @Override
    1.95 -    public long getLastModified() {
    1.96 -        return lastModified;
    1.97 -    }
    1.98 -
    1.99 -    @Override
   1.100 -    public boolean delete() {
   1.101 -        return false;
   1.102 -    }
   1.103 -
   1.104 -    byte[] getContent() {
   1.105 -        return content;
   1.106 -    }
   1.107 -
   1.108 -    private class CloseStream extends OutputStream {
   1.109 -
   1.110 -        private final ByteArrayOutputStream delegate;
   1.111 -
   1.112 -        CloseStream() {
   1.113 -            delegate = new ByteArrayOutputStream();
   1.114 -        }
   1.115 -
   1.116 -        @Override
   1.117 -        public void write(int b) throws IOException {
   1.118 -            delegate.write(b);
   1.119 -        }
   1.120 -
   1.121 -        @Override
   1.122 -        public void write(byte[] b) throws IOException {
   1.123 -            delegate.write(b);
   1.124 -        }
   1.125 -
   1.126 -        @Override
   1.127 -        public void write(byte[] b, int off, int len) throws IOException {
   1.128 -            delegate.write(b, off, len);
   1.129 -        }
   1.130 -
   1.131 -        @Override
   1.132 -        public void close() throws IOException {
   1.133 -            delegate.close();
   1.134 -            content = delegate.toByteArray();
   1.135 -            lastModified = System.currentTimeMillis();
   1.136 -        }                                    
   1.137 -
   1.138 -    }
   1.139 -
   1.140 -}