哪个表现更多:子字符串或手动方法?

问题描述 投票:0回答:1
“ home/static/9/953/9537746.jpg”(第一个字符image =名称目录) 在URL中,隐藏图像位置的实际地址。

www.mywebsite.com/book/9537746.jpg

我的servlet从图像名称(前三个字符)计算路径。由于页面上可能有很多图像,因此还会有许多这样的请求。我想实现最高的性能。这种方法会起作用,还是有一种方法可以改善它? .... @WebServlet(name = "ZeroCopyServlet", urlPatterns = {"/book"}) ... char[] chars = requestedFile.toCharArray(); char[] firstChar = new char[1]; char[] firstThreeChars = new char[3]; System.arraycopy(chars, 0, firstThreeChars, 0, 3); System.arraycopy(chars, 0, firstChar, 0, 1); String result1 = new String(firstChar); String result2 = new String(firstThreeChars); requestedFile = result1 + "/" + result2 + "/" + requestedFile; Path filePath = basePath.resolve(requestedFile).normalize(); ... fileChannel.transferTo ... 所有用于计算目录的逻辑与将照片从服务器提供到客户端的逻辑(Zerocopy)结合使用。也许我在做错一切,将这种逻辑放在servlet中是不好的做法。谢谢您的建议。

你可以通过正直来做到这一点
https://regex101.com/r/yeakju

java servlets
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.