All Downloads are FREE. Search and download functionalities are using the official Maven repository.

juzu.impl.fs.FileSystemScanner Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
/*
 * Copyright 2013 eXo Platform SAS
 *
 * Licensed 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 juzu.impl.fs;

import juzu.impl.common.Resource;
import juzu.impl.fs.spi.ReadFileSystem;
import juzu.impl.common.Tools;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

/** @author Julien Viet */
public abstract class FileSystemScanner

implements Filter

{ public static

FileSystemScanner

createTimestamped(ReadFileSystem

fs) { return new Timestamped

(fs); } public static

FileSystemScanner

createHashing(ReadFileSystem

fs) { return new Hash

(fs); } public static class Timestamped

extends FileSystemScanner

{ public Timestamped(ReadFileSystem

fs) { super(fs); } @Override protected long stampOf(P file) throws IOException { return fs.getLastModified(file); } @Override protected boolean isModified(long snapshot, long current) { return snapshot < current; } } public static class Hash

extends FileSystemScanner

{ public Hash(ReadFileSystem

fs) { super(fs); } @Override protected long stampOf(P file) throws IOException { juzu.impl.common.Timestamped resource = fs.getResource(file); InputStream in = resource.getObject().getInputStream(); byte[] bytes = Tools.bytes(in); return Tools.md5(bytes); } @Override protected boolean isModified(long snapshot, long current) { return snapshot != current; } } /** . */ protected final ReadFileSystem

fs; /** . */ final ArrayList stack = new ArrayList(); private FileSystemScanner(ReadFileSystem

fs) { this.fs = fs; } public ReadFileSystem

getFileSystem() { return fs; } public Snapshot

take() { return new Snapshot

(this); } public boolean acceptDir(P dir, String name) throws IOException { return !name.startsWith("."); } public boolean acceptFile(P file, String name) throws IOException { return !name.startsWith("."); } protected abstract long stampOf(P file) throws IOException; protected abstract boolean isModified(long snapshot, long current); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy