Java tutorial
package ch.cyberduck.core.b2; /* * Copyright (c) 2002-2016 iterate GmbH. All rights reserved. * https://cyberduck.io/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import ch.cyberduck.core.DisabledConnectionCallback; import ch.cyberduck.core.Path; import ch.cyberduck.core.PathAttributes; import ch.cyberduck.core.exception.BackgroundException; import ch.cyberduck.core.features.Touch; import ch.cyberduck.core.features.Write; import ch.cyberduck.core.io.Checksum; import ch.cyberduck.core.io.DefaultStreamCloser; import ch.cyberduck.core.io.StatusOutputStream; import ch.cyberduck.core.transfer.TransferStatus; import org.apache.commons.io.input.NullInputStream; import synapticloop.b2.response.B2FileResponse; import synapticloop.b2.response.BaseB2Response; public class B2TouchFeature implements Touch<BaseB2Response> { private Write<BaseB2Response> writer; public B2TouchFeature(final B2Session session) { this.writer = new B2WriteFeature(session); } @Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if (Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(new NullInputStream(0L), status)); } status.setTimestamp(System.currentTimeMillis()); final StatusOutputStream<BaseB2Response> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(file.getParent(), file.getName(), file.getType(), new PathAttributes(file.attributes()) .withVersionId(((B2FileResponse) out.getStatus()).getFileId())); } @Override public boolean isSupported(final Path workdir) { // Creating files is only possible inside a bucket. return !workdir.isRoot(); } @Override public B2TouchFeature withWriter(final Write<BaseB2Response> writer) { this.writer = writer; return this; } }