2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ftpupload.internal.ftp;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
18 import java.util.List;
20 import org.apache.ftpserver.ftplet.FtpFile;
21 import org.openhab.core.util.HexUtils;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Simple FTP file implementation.
29 * @author Pauli Anttila - Initial contribution
31 public class SimpleFtpFile implements FtpFile {
32 private Logger logger = LoggerFactory.getLogger(SimpleFtpFile.class);
36 public byte[] getData() {
37 return file.getData();
41 public InputStream createInputStream(long arg0) throws IOException {
42 logger.trace("createInputStream: {}", arg0);
47 public OutputStream createOutputStream(long arg0) throws IOException {
48 logger.trace("createOutputStream: {}", arg0);
49 file = new MyOutputStream();
54 public boolean delete() {
55 logger.trace("delete");
60 public boolean doesExist() {
61 logger.trace("doesExist");
66 public String getAbsolutePath() {
67 logger.trace("getAbsolutePath");
72 public String getGroupName() {
73 logger.trace("getGroupName");
78 public long getLastModified() {
79 logger.trace("getLastModified");
84 public int getLinkCount() {
85 logger.trace("getLinkCount");
90 public String getName() {
91 logger.trace("getName");
96 public String getOwnerName() {
97 logger.trace("getOwnerName");
102 public long getSize() {
103 logger.trace("getSize");
108 public boolean isDirectory() {
109 logger.trace("isDirectory");
114 public boolean isFile() {
115 logger.trace("isFile");
120 public boolean isHidden() {
121 logger.trace("isHidden");
126 public boolean isReadable() {
127 logger.trace("isReadable");
132 public boolean isRemovable() {
133 logger.trace("isRemovable");
138 public boolean isWritable() {
139 logger.trace("isWritable");
144 public List<FtpFile> listFiles() {
145 logger.trace("listFiles");
150 public boolean mkdir() {
151 logger.trace("mkdir");
156 public boolean move(FtpFile arg0) {
157 logger.trace("move: {}", arg0);
162 public boolean setLastModified(long arg0) {
163 logger.trace("setLastModified: {}", arg0);
168 public Object getPhysicalFile() {
169 logger.trace("getPhysicalFile");
173 private class MyOutputStream extends OutputStream {
174 private StringBuilder data = new StringBuilder();
177 public void write(int b) throws IOException {
178 data.append(String.format("%02X", (byte) b));
181 public byte[] getData() {
183 byte[] d = HexUtils.hexToBytes(data.toString());
184 logger.debug("File len: {}", d.length);
186 } catch (IllegalArgumentException e) {
187 logger.debug("Exception occured during data conversion: {}", e.getMessage());