mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
fix getName
This commit is contained in:
@@ -57,7 +57,7 @@ public class ResourceClassLoader<T extends Resource> extends SecureClassLoader {
|
||||
* @return this
|
||||
*/
|
||||
public ResourceClassLoader<T> addResource(final T resource) {
|
||||
this.resourceMap.put(resource.name(), resource);
|
||||
this.resourceMap.put(resource.getName(), resource);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ public class ZipUtil {
|
||||
*
|
||||
* @param zipFile 生成的Zip文件,包括文件名。注意:zipPath不能是srcPath路径下的子文件夹
|
||||
* @param charset 编码
|
||||
* @param resources 需要压缩的资源,资源的路径为{@link Resource#name()}
|
||||
* @param resources 需要压缩的资源,资源的路径为{@link Resource#getName()}
|
||||
* @return 压缩文件
|
||||
* @throws HutoolException IO异常
|
||||
* @since 5.5.2
|
||||
|
||||
@@ -189,14 +189,14 @@ public class ZipWriter implements Closeable {
|
||||
/**
|
||||
* 添加资源到压缩包,添加后关闭资源流
|
||||
*
|
||||
* @param resources 需要压缩的资源,资源的路径为{@link Resource#name()}
|
||||
* @param resources 需要压缩的资源,资源的路径为{@link Resource#getName()}
|
||||
* @return this
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public ZipWriter add(final Resource... resources) throws IORuntimeException {
|
||||
for (final Resource resource : resources) {
|
||||
if (null != resource) {
|
||||
add(resource.name(), resource.getStream());
|
||||
add(resource.getName(), resource.getStream());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -395,7 +395,7 @@ public class DelegatePath extends SimpleWrapper<Path> implements Path, Resource
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String getName() {
|
||||
return PathUtil.getName(this.raw);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class BytesResource implements Resource, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class FileObjectResource implements Resource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String getName() {
|
||||
return this.fileObject.getName();
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ public class FileResource implements Resource, Serializable {
|
||||
// ----------------------------------------------------------------------- Constructor end
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ public class HttpResource implements Resource, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return resource.name();
|
||||
public String getName() {
|
||||
return resource.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,7 +74,7 @@ public class InputStreamResource implements Resource, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ public class MultiResource implements Resource, Iterable<Resource>, Iterator<Res
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return resources.get(getValidCursor()).name();
|
||||
public String getName() {
|
||||
return resources.get(getValidCursor()).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,7 @@ public interface Resource {
|
||||
* @return 资源名
|
||||
* @since 4.0.13
|
||||
*/
|
||||
String name();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* 获得解析后的{@link URL},无对应URL的返回{@code null}
|
||||
|
||||
@@ -319,7 +319,7 @@ public class ResourceUtil {
|
||||
public static void loadTo(final Properties properties, final Resource resource, final Charset charset) {
|
||||
Assert.notNull(properties);
|
||||
Assert.notNull(resource);
|
||||
final String filename = resource.name();
|
||||
final String filename = resource.getName();
|
||||
if (filename != null && StrUtil.endWithIgnoreCase(filename, ".xml")) {
|
||||
// XML
|
||||
try (final InputStream in = resource.getStream()) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class UrlResource implements Resource, Serializable {
|
||||
//-------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class VfsResource implements Resource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String getName() {
|
||||
return MethodUtil.invoke(virtualFile, VIRTUAL_FILE_METHOD_GET_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ class MultiResourceTest {
|
||||
assertEquals(0, getCursorValue(multiResource), "游标应该更新为0");
|
||||
|
||||
// 验证getName方法使用的是第一个资源
|
||||
assertEquals("resource1", multiResource.name(), "getName应该返回第一个资源名称");
|
||||
assertEquals("resource1", multiResource.getName(), "getName应该返回第一个资源名称");
|
||||
|
||||
// 第二次调用next()
|
||||
final Resource result2 = multiResource.next();
|
||||
@@ -109,7 +109,7 @@ class MultiResourceTest {
|
||||
assertEquals(1, getCursorValue(multiResource), "游标应该更新为1");
|
||||
|
||||
// 验证getName方法使用的是第二个资源
|
||||
assertEquals("resource2", multiResource.name(), "getName应该返回第二个资源名称");
|
||||
assertEquals("resource2", multiResource.getName(), "getName应该返回第二个资源名称");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +142,7 @@ class MultiResourceTest {
|
||||
multiResource.remove();
|
||||
|
||||
assertEquals(2, getInternalSize(multiResource), "删除后资源数量应该是2");
|
||||
assertEquals("resource2", multiResource.name(), "删除后getName应该返回第二个资源名称");
|
||||
assertEquals("resource2", multiResource.getName(), "删除后getName应该返回第二个资源名称");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,11 +265,11 @@ class MultiResourceTest {
|
||||
/**
|
||||
* 测试Resource接口的实现类,用于单元测试
|
||||
*/
|
||||
private record TestResource(String name, String content) implements Resource {
|
||||
private record TestResource(String getName, String content) implements Resource {
|
||||
@Override
|
||||
public URL getUrl() {
|
||||
try {
|
||||
return new URL("http://example.com/" + name);
|
||||
return new URL("http://example.com/" + getName);
|
||||
} catch (final MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ResourceUtilTest {
|
||||
@Test
|
||||
public void stringResourceTest(){
|
||||
final StringResource stringResource = new StringResource("testData", "test");
|
||||
Assertions.assertEquals("test", stringResource.name());
|
||||
Assertions.assertEquals("test", stringResource.getName());
|
||||
Assertions.assertArrayEquals("testData".getBytes(), stringResource.readBytes());
|
||||
Assertions.assertArrayEquals("testData".getBytes(), IoUtil.readBytes(stringResource.getStream()));
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class ResourceUtilTest {
|
||||
@Test
|
||||
public void fileResourceTest(){
|
||||
final FileResource resource = new FileResource(FileUtil.file("test.xml"));
|
||||
Assertions.assertEquals("test.xml", resource.name());
|
||||
Assertions.assertEquals("test.xml", resource.getName());
|
||||
Assertions.assertTrue(StrUtil.isNotEmpty(resource.readUtf8Str()));
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ public class MultipartOutputStream extends OutputStream {
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
private void appendResource(final String formFieldName, final Resource resource) throws IORuntimeException {
|
||||
final String fileName = resource.name();
|
||||
final String fileName = resource.getName();
|
||||
|
||||
// Content-Disposition
|
||||
if (null == fileName) {
|
||||
|
||||
Reference in New Issue
Block a user