Package com.nexirius.tools.dirsync

Source Code of com.nexirius.tools.dirsync.FileInfo

//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.tools.dirsync;

import com.nexirius.util.TextToken;

import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.io.IOException;

public class FileInfo {

    public static TextToken SPACE = new TextToken(' ');
    public static TextToken NEW_LINE = new TextToken('\n');
    public static final String FILE_IDENTIFIER_STRING = "F";
    public static TextToken FILE_IDENTIFIER = new TextToken(FILE_IDENTIFIER_STRING, TextToken.IDENTIFIER);
    public String name;
    public long size;
    public long hash;
    public DirSyncStatus status;

    public String getName() {
        return name;
    }

    public long getSize() {
        return size;
    }

    public long getHash() {
        return hash;
    }

    public boolean isDifferent(FileInfo other) {
        if (other.getSize() != getSize() || other.getHash() != getHash()) {
            return true;
        }

        return false;
    }

    public void getString(StringBuffer sb) {
        sb.append(name);
        sb.append('\n');
        sb.append(size);
        sb.append('\n');
        sb.append(hash);
        sb.append('\n');
    }

    public TextToken getIdentifier()
    {
        return FILE_IDENTIFIER;
    }

    public void writeTo(OutputStream out) throws Exception {
        getIdentifier().writeTo(out);
        SPACE.writeTo(out);
        new TextToken(name).writeTo(out);
        SPACE.writeTo(out);
        new TextToken(size).writeTo(out);
        SPACE.writeTo(out);
        new TextToken(hash).writeTo(out);
        NEW_LINE.writeTo(out);
    }

    public void readFrom(PushbackInputStream in) throws IOException {
        TextToken token = TextToken.nextToken(in);

        if (token.isString()) {
            name = token.getString();
        } else {
            throw new IOException("Unexpected Token (expect name):" + token);
        }

        token = TextToken.nextToken(in);

        if (token.isLong()) {
            size = token.getLong();
        } else {
            throw new IOException("Unexpected Token (expect size):" + token);
        }

        token = TextToken.nextToken(in);

        if (token.isLong()) {
            hash = token.getLong();
        } else {
            throw new IOException("Unexpected Token (expect hash):" + token);
        }
    }
}
TOP

Related Classes of com.nexirius.tools.dirsync.FileInfo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.