1. Example
/** * 获取资源 * * @param request 请求 * @param response 响应 */ @RequestMapping("/getFile") public void getFile(HttpServletRequest request, HttpServletResponse response) { //请求信息 String version = request.getParameter("version"); String data = request.getParameter("data"); String platform = request.getParameter("platform"); //获取版本文件 String xmlPath =""; try { File path = new File(ResourceUtils.getURL("classpath:").getPath()); while (true) { File parentFile = path.getParentFile(); if (parentFile.getParent().endsWith("mapleStoryBackstage")) { xmlPath = parentFile.getParent() +"/assetBundles/"+ platform +"/version.xml"; break; } else { path = path.getParentFile(); } } } catch (FileNotFoundException e) { e.printStackTrace();} //Verify version AssetBundleVersion serverAssetBundleVersion = appService.assetBundleVersionXmlDecode(new File(xmlPath)); ConcurrentHashMap serverAssetBundleMap = serverAssetBundleVersion.getAssetBundleMap(); ListassetBundleList = new ArrayList<>(); if (StringUtils.isBlank(data)) { LogManger.info("首次更新资源"); serverAssetBundleMap.values().forEach(assetBundle -> assetBundleList.add(assetBundle.getUrl())); } else if (version.equals(serverAssetBundleVersion.getVersion())) { LogManger.info("已是最新版"); return; } else { //资源比对 LogManger.info("增量更新资源"); ListassetBundleList1 = JSONArray.parseArray(data, AssetBundle.class); Map a = new ConcurrentHashMap<>(); assetBundleList1.forEach(assetBundle -> { AssetBundle assetBundle1 = a.get(assetBundle.getName()); if (null == assetBundle1) { a.put(assetBundle.getName(), assetBundle); } else { System.out.println(assetBundle.getName()); } }); Map clientAssetBundleMap = JSONArray.parseArray(data, AssetBundle.class).stream().collect(Collectors.toMap(AssetBundle::getName, (p) -> p)); serverAssetBundleMap.forEach((key, value) -> { AssetBundle assetBundle = clientAssetBundleMap.get(key); if (null == assetBundle) { assetBundleList.add(value.getUrl()); } else { if (!value.getMd5().equals(assetBundle.getMd5())) { assetBundleList.add(value.getUrl()); } } }); } //资源目录 String destFileName ="assetBundle"; String[] split = xmlPath.split("/"); StringBuilder basePath = new StringBuilder(); for (int i = 0; i < split.length - 1; i++) { basePath.append(split[i]).append("/"); } //创建压缩文件 FileOutputStream fileOutputStream; ZipOutputStream zipOutputStream; FileInputStream fileInputStream = null; File zipFile = new File(platform +"_"+ destFileName +".zip"); try { fileOutputStream = new FileOutputStream(zipFile.getName()); zipOutputStream = new ZipOutputStream(fileOutputStream); for (String path : assetBundleList) { addToZip(fileInputStream, basePath, zipOutputStream, path); } addToZip(fileInputStream, basePath, zipOutputStream,"WindowsPlayer"); zipOutputStream.closeEntry(); zipOutputStream.close(); if (fileInputStream != null) { fileInputStream.close(); } fileOutputStream.close(); byte[] fileBytes = FileUtil.readFileToByteArray(zipFile); byte[] versionBytes = serverAssetBundleVersion.getVersion().getBytes(); ByteBuf byteBuf = Unpooled.copiedBuffer(ByteUtil.int2Bytes(versionBytes.length), versionBytes, fileBytes); byte[] bytes = new byte[byteBuf.readableBytes()]; byteBuf.readBytes(bytes); //通过response发送数据 response.setCharacterEncoding("UTF-8"); response.setHeader("Content-disposition","attachment; filename="+ platform +"_"+ destFileName); response.setContentLength(bytes.length); response.setContentType("multipart/form-data"); InputStream in = new ByteArrayInputStream(bytes); OutputStream out = response.getOutputStream(); int b; byte[] bufferOut = new byte[1024]; while ((b = in.read(bufferOut)) != -1) { out.write(bufferOut, 0, b); } out.close(); in.close(); zipFile.delete(); } catch (IOException e) { e.printStackTrace(); } }

java--game backend--project development summary 6--resource download Related posts

  1. how to rename variable/method and all references in it in C# VSCode?

    I saw how to do it in javascript: https://johnpapa.net/refactoring-with-visual-studio-code/But for some reason it doesn't seem to work with C#.Solution:You can select a piece of text and right click on it. The context menu has"Change All Events". But it only works with open files in the editor. ...

  2. python – Django JSONField in ArrayField

    I'm having trouble inserting a field using an ArrayField with JSONField.models.pylocations = ArrayField(JSONField(null = True, blank = True), blank=True, null = True)insertlocation_arr = [{"locations":"loc1","amount":Decimal(100.00)},{"locations":"loc2","amount":Decimal(200.25)}]instance.locations = ...

  3. Python dictionary/loop output

    &gt; Make a dictionary for the nine Tampa Bay Rays. Use the player name as a key and a list of each value. &gt; Each value list should hold the batting order where the player plays, and the current batting average. Go to See above. &gt; Once the dictionary is done, use a for loop to display the dict ...

  4. java - ArrayIndexOutOfBoundsException error while parsing JSON data

    I get ArrayIndexOutOfBoundsException at id[i] = c.getString(TAG_ID);Here is the code:for (int i = 0; i &lt; 25; i++) { JSONObject c = contacts.getJSONObject(i); id[i] = c.getString(TAG_ID);}I've checked that the JSON file contains 25 objects. I've also tried with i &lt; 10 but it still gives the sam ...

  5. python several ways to detect mining features

    Computer performance:①cpu and memory usage (common):How to get the usage of cpu and memory in real time in python②The remaining capacity of the c drive (some mining programs will occupy a lot of memory on the c drive):Python implements 2 methods for obtaining remaining disk space③ Directly kill the ...

  6. Javascript request SSL request

    For our APP, we have a web application and an API service, on a certain event, the web application polls the api service using Javascript to know the status of the event. Both applications are in a separate HTTPS sub domain, and has a self-signed certificate (since it's still in alpha). The problem ...

  7. netty source code analysis (4.0)-21 ByteBuf's design principle

    The io.netty.buffer package is an implementation of netty ByteBuf. ByteBuf is an abstract interface for binary buffers. Its functions are:Random access and sequential access are possible.Supports serialization and deserialization of primitive data types (byte, short, int, long, float, double).The un ...

  8. php - prevent Excel from reformatting text in scientific notation

    I have a PHP script that exports data from a database to different formats, including as an Excel document. If a text field contains a value such as 123123123123, Excel converts it to 1.23123E 11 by default. Is it possible to prevent this Absolutely unnecessary behavior?Solution:If your goal is to s ...

  9. python - add horizontal lines that support page layout to ReportLab table layout

    I'm using ReportLab to build a PDF with a table with most of the content.To help visually distinguish the lines, I'd like to put a horizontal line after each line, as long as it's not the last line on the page.To put a horizontal line after each row, I can use TableStyle:style = TableStyle([ ("LINEB ...

  10. PHP-Json encoding string with spaces

    I'm developing metabox class for wordpress and specifically implement Media Uploading which was introduced in 3.5. For passing options between metabox class and media uploader, I like to use json. The basic data structure I have is as follows ($data_ar).Array( [uploader_title] =&gt; Upload or choose ...

Recent Posts

  1. javascript-Hover function realization

    I want to use Hover on the contact title text. I want the displayed content to follow the cursor as well. I made a jsfiddle with my hover, but I don’t know why it doesn’t work...HTML Contact Title Text DisplayedCSS.SignatureBox { display: none; width: 200px; height: 30px; background-color: #F9F7F7; border: 1px solid #e4e4e4; }JS$(document).ready(function() { $('.SignatureBox').hide(); $('.toggleSwitch_j').hover(function () { $(this).children('.SignatureBox').show(); }, function () { $(this).chil...

  2. java-OutofMemoryError when reading large files

    I am trying to read several large files (over 100MB). So far, it always breaks in the middle of OutofMemory Error. Is there any solution?FileInputStream fstream = new FileInputStream(f); // Get the object of DataInputStream DataInputStream dain = new DataInputStream(fstream); // BufferedReader br = new BufferedReader(new InputStreamReader(in)); BufferedReader in = new BufferedReader(new InputStreamReader(dain)); String text = in.readLine(); while(text != null) { stat(text); text = in.readLine(...

  3. java-libGDX application to .exe?

    I have a libGDX project and want to be able to run it from an .exe file on the desktop.So far, I can only run it on DesktopLauncher inside Android Studio.What is the easiest way to build an .exe file from a project?I can build a .jar file, but I can’t double-click to run it. Does this mean I need to package it for display or something else?I am new to libgdx and android studio, I just need to deploy my first simple application as a standalone file on the desktop.Solution:Two options:1- Packr, it...

  4. System.MissingMethodException when trying to read ZipFile from ZipArchive C#

    See answer in English &gt; C# .NET Missing Method Exception when opening ZipArchive created with System.IO.Compression 2 I have a C#.NET (v4.6.2) WinForms application and I am accessing a file which may/may not be .zip archive created with"System.IO.Compression;". I have"System.IO.Compression"and Sy...

  5. ceph distributed storage-MDS introduction

    1. mds storageMemory cache of metadata, in order to speed up the access of metadata.The metadata of the file system is saved (the names and inode numbers of subdirectories and subfiles are saved in the object)It also saves the cephfs log journal, which is used to restore the metadata cache in mdsWhen restarting mds, the previously cached metadata will be loaded from the osd through replay2. mds cold standby/hot standbyCold standby is the backup mds, which only serves as a process backup and does...

  6. JavaScript stack and queue

    Stack and queue: JavaScript does not have a dedicated stack and queue, it is simulated by [array]Stack: One end is closed and the other end is opened. The first entered is at the bottom. When to use: When the last element of the array is always used, the stack structureQueue: It is an ordered collec...

  7. python - how to list[n] points to list[0]? Get items out of order

    I'm not sure about the terminology of this technique. I want to create a list that will"loop"if I try to access an element outside the scope of the list. Example of behavior I'd like to achieve:&gt;&gt;&gt; musical_scale = ['C', 'D', 'E', 'F', 'G', 'A', 'B']&gt;&gt;&gt; musical_scale[2]E&gt;&gt;&gt;...

  8. python: if row [1] .upper().find(brand)! = – 1:

    Are these two statements the same?if row[1].upper().find(brand)!=-1:andif row[1].upper().find(brand):Solution:No, they are not equal. In Python, any non-zero number is considered True, so if the expression evaluates to -1, the second statement will be considered true; if the expression evaluates to 0 , Then the second statement will be considered false (when it should be true).Use the first statement....

  9. java-setup Openfire in Mac OS X

    I have installed openfire 3.9.3 on MAC OS X Yosemite version 10.10.2. Having trouble setting up openfire. After installing openfire, I am getting errors like cannot start openfire.Solution:To get the latest version of java (jdk) and install and install the latest version of openfire .its works fine...

  10. Python learning 09: define function

    This time we create Demo02.py under the com.second.function created last time. In Python, to define a function, use the def statement, use the function name, parentheses, parameters in parentheses, and colon: in turn, and then indent the block The function body is written in the function body, and t...