package com.github.x19990416.macrossx.spring.component.remotefile;

import java.io.InputStream;
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

public interface IRemoteFileService {
	final static String URL_SEPARATOR = "/";

	default boolean save(InputStream in) {
		return save(in, null);
	}

	default boolean save(InputStream in, String subUrl) {
		return save(in, subUrl, UUID.randomUUID().toString());
	}

	boolean save(InputStream in, String subUrl, String name);

	default byte[] load(String name) {
		return load(null, name);
	}

	byte[] load(String subUrl, String name);

	default boolean remove(String name) {
		return remove(null, name);
	}

	boolean remove(String subUrl, String name);

	default List<String> list() {
		return list(null);
	}

	List<String> list(String subUrl);

	default String combineUrl(String baseUrl, String subUrl) {
		if (StringUtils.isEmpty(subUrl))
			return baseUrl;

		if (baseUrl.endsWith(URL_SEPARATOR))
			return baseUrl + subUrl;
		else
			return baseUrl + URL_SEPARATOR + subUrl;
	}
}

@@ -116,32 +116,8 @@
 st;%0A
-import java.util.UUID;%0A%0A
 impo
@@ -157,16 +157,16 @@
 gUtils;%0A
+
 %0Apublic 
@@ -279,150 +279,53 @@
 m in
-) %7B%0A%09%09return save(in, null);%0A%09%7D%0A%0A%09default boolean save(InputStream in, String subUrl) %7B%0A%09%09return save(in, subUrl, UUID.randomUUID().toString()
+, String name) %7B%0A%09%09return save(in, null, name
 );%0A%09

save method IRemoteFileService shall not create a random name