Compressing and Decompressing Data using JavaTM APIs

decompress.java java解压缩zip和rarjava解压缩zip和rarjava解压缩zip和rar 立即下载

Compressing and Decompressing Data using JavaTM APIs

by Qusay H. Mahmoud
with contributions from Konstantin Kladko

February 2002

Many sources of information contain redundant data or data that adds little to the stored information. This results in tremendous amounts of data being transferred between client and server applications or computers in general. The obvious solution to the problems of data storage and information transfer is to install additional storage devices and expand existing communication facilities. To do so, however, requires an increase in an organization's operating costs. One method to alleviate a portion of data storage and information transfer is through the representation of data by more efficient code. This article presents a brief introduction to data compression and decompression, and shows how to compress and decompress data, efficiently and conveniently, from within your JavaTM applications using the java.util.zip package.

While it is possible to compress and decompress data using tools such as WinZip, gzip, and Java ARchive (or jar), these tools are used as standalone applications. It is possible to invoke these tools from your Java applications, but this is not a straightforward approach and not an efficient solution. This is especially true if you wish to compress and decompress data on the fly (before transferring it to a remote machine for example). This article:

  • Gives you a brief overview of data compression
  • Describes the java.util.zip package
  • Shows how to use this package to compress and decompress data
  • Shows how to compress and decompress serialized objects to save disk space
  • Shows how to compress and decompress data on the fly to improve the performance of client/server applications

Overview of Data Compression

The simplest type of redundancy in a file is the repetition of characters. For example, consider the following string:

BBBBHHDDXXXXKKKKWWZZZZ

This string can be encoded more compactly by replacing each repeated string of characters by a single instance of the repeated character and a number that represents the number of times it is repeated. The earlier string can be encoded as follows:

4B2H2D4X4K2W4Z

Here "4B" means four B's, and 2H means two H's, and so on. Compressing a string in this way is called run-length encoding.

As another example, consider the storage of a rectangular image. As a single color bitmapped image, it can be stored as shown in Figure 1.

figure 1

Figure 1: A bitmap with information for run-length encoding

Another approach might be to store the image as a graphics metafile:

Rectangle 11, 3, 20, 5

This says, the rectangle starts at coordinate (11, 3) of width 20 and length 5 pixels.

The rectangular image can be compressed with run-length encoding by counting identical bits as follows:

0, 40
0, 40
0,10 1,20 0,10
0,10 1,1 0,18 1,1 0,10
0,10 1,1 0,18 1,1 0,10
0,10 1,1 0,18 1,1 0,10
0,10 1,20 0,10
0,40

The first line above says that the first line of the bitmap consists of 40 0's. The third line says that the third line of the bitmap consists of 10 0's followed by 20 1's followed by 10 more 0's, and so on for the other lines.

Note that run-length encoding requires separate representations for the file and its encoded version. Therefore, this method cannot work for all files. Other compression techniques include variable-length encoding (also known as Huffman Coding), and many others. For more information, there are many books available on data and image compression techniques.

There are many benefits to data compression. The main advantage of it, however, is to reduce storage requirements. Also, for data communications, the transfer of compressed data over a medium results in an increase in the rate of information transfer. Note that data compression can be implemented on existing hardware by software or through the use of special hardware devices that incorporate compression techniques. Figure 2 shows a basic data-compression block diagram.

figure 2
Figure 2: Data-compression block diagram
ZIP vs. GZIP

If you are working on Windows, you might be familiar with the WinZip tool, which is used to create a compressed archive and to extract files from a compressed archive. On UNIX, however, things are done a bit differently. The tar command is used to create an archive (not compressed) and another program (gzip or compress) is used to compress the archive.

Tools such as WinZip and PKZIP act as both an archiver and a compressor. They compress files and store them in an archive. On the other hand, gzip does not archive files. Therefore, on UNIX, the tar command is usually used to create an archive then the gzip command is used to compress the archived file.

The java.util.zip Package

Java provides the java.util.zip package for zip-compatible data compression. It provides classes that allow you to read, create, and modify ZIP and GZIP file formats. It also provides utility classes for computing checksums of arbitrary input streams that can be used to validate input data. This package provides one interface, fourteen classes, and two exception classes as shown in Table 1.

Table 1: The java.util.zip package

ItemTypeDescription
ChecksumInterfaceRepresents a data checksum. Implemented by the classes Adler32 and CRC32
Adler32ClassUsed to compute the Adler32 checksum of a data stream
CheckedInputStreamClassAn input stream that maintains the checksum of the data being read
CheckedOutputStreamClassAn output stream that maintains the checksum of the data being written
CRC32ClassUsed to compute the CRC32 checksum of a data stream
DeflaterClassSupports general compression using the ZLIB compression library
DeflaterOutputStreamClassAn output stream filter for compressing data in the deflate compression format
GZIPInputStreamClassAn input stream filter for reading compressed data in the GZIP file format
GZIPOutputStreamClassAn output stream filter for writing compressed data in the GZIP file format
InflaterClassSupports general decompression using the ZLIB compression library
InlfaterInputStreamClassAn input stream filter for decompressing data in the deflate compression format
ZipEntryClassRepresents a ZIP file entry
ZipFileClassUsed to read entries from a ZIP file
ZipInputStreamClassAn input stream filter for reading files in the ZIP file format
ZipOutputStreamClassAn output stream filter for writing files in the ZIP file format
DataFormatExceptionException ClassThrown to signal a data format error
ZipExceptionException ClassThrown to signal a zip error


Note: The ZLIB compression library was initially developed as part of the Portable Network Graphics (PNG) standard that is not protected by patents.

Decompressing and Extracting Data from a ZIP file

The java.util.zip package provides classes for data compression and decompression. Decompressing a ZIP file is a matter of reading data from an input stream. The java.util.zip package provides a ZipInputStream class for reading ZIP files. A ZipInputStream can be created just like any other input stream. For example, the following segment of code can be used to create an input stream for reading data from a ZIP file format:

FileInputStream fis = new FileInputStream("figs.zip");
ZipInputStream zin = new 
  ZipInputStream(new BufferedInputStream(fis));

Once a ZIP input stream is opened, you can read the zip entries using the getNextEntry method which returns a ZipEntry object. If the end-of-file is reached, getNextEntry returns null:

ZipEntry entry;
while((entry = zin.getNextEntry()) != null) {
   // extract data
   // open output streams
}

Now, it is time to set up a decompressed output stream, which can be done as follows:

int BUFFER = 2048;
FileOutputStream fos = new 
  FileOutputStream(entry.getName());
BufferedOutputStream dest = new 
  BufferedOutputStream(fos, BUFFER);


Note: In this segment of code we have used the BufferedOutputStream instead of the ZIPOutputStream. The ZIPOutputStream and the GZIPOutputStream use internal buffer sizes of 512. The use of the BufferedOutputStream is only justified when the size of the buffer is much more than 512 (in this example it is set to 2048). While the ZIPOutputStream doesn't allow you to set the buffer size, in the case of the GZIPOutputStream however, you can specify the internal buffer size as a constructor argument.

In this segment of code, a file output stream is created using the entry's name, which can be retrieved using the entry.getName method. Source zipped data is then read and written to the decompressed stream:

while ((count = zin.read(data, 0, BUFFER)) != -1) {
   //System.out.write(x);
   dest.write(data, 0, count);
}

And finally, close the input and output streams:

dest.flush();
dest.close();
zin.close();

The source program in Code Sample 1 shows how to decompress and extract files from a ZIP archive. To test this sample, compile the class and run it by passing a compressed file in ZIP format:

prompt> java UnZip somefile.zip

Note that somefile.zip could be a ZIP archive created using any ZIP-compatible tool, such as WinZip.

Code Sample 1: UnZip.java

import java.io.*;
import java.util.zip.*;

public class UnZip {
   final int BUFFER = 2048;
   public static void main (String argv[]) {
      try {
         BufferedOutputStream dest = null;
         FileInputStream fis = new 
	   FileInputStream(argv[0]);
         ZipInputStream zis = new 
	   ZipInputStream(new BufferedInputStream(fis));
         ZipEntry entry;
         while((entry = zis.getNextEntry()) != null) {
            System.out.println("Extracting: " +entry);
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            FileOutputStream fos = new 
	      FileOutputStream(entry.getName());
            dest = new 
              BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) 
              != -1) {
               dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
         }
         zis.close();
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

It is important to note that the ZipInputStream class reads ZIP files sequentially. The class ZipFile, however, reads the contents of a ZIP file using a random access file internally so that the entries of the ZIP file do not have to be read sequentially.


Note: Another fundamental difference between ZIPInputStream and ZipFile is in terms of caching. Zip entries are not cached when the file is read using a combination of ZipInputStream and FileInputStream. However, if the file is opened using ZipFile(fileName) then it is cached internally, so if ZipFile(fileName) is called again the file is opened only once. The cached value is used on the second open. If you work on UNIX, it is worth noting that all zip files opened using ZipFile are memory mapped, and therefore the performance of ZipFile is superior to ZipInputStream. If the contents of the same zip file, however, are be to frequently changed and reloaded during program execution, then using ZipInputStream is preferred.

This is how a ZIP file can be decompressed using the ZipFile class:

  1. Create a ZipFile object by specifying the ZIP file to be read either as a String filename or as a File object:

    ZipFile zipfile = new ZipFile("figs.zip");

  2. Use the entries method, returns an Enumeration object, to loop through all the ZipEntry objects of the file:
    while(e.hasMoreElements()) {
       entry = (ZipEntry) e.nextElement();
       // read contents and save them
    }
    
  3. Read the contents of a specific ZipEntry within the ZIP file by passing the ZipEntry to getInputStream, which will return an InputStream object from which you can read the entry's contents:
    is = new 
      BufferedInputStream(zipfile.getInputStream(entry));
    

  4. Retrieve the entry's filename and create an output stream to save it:
    byte data[] = new byte[BUFFER];
    FileOutputStream fos = new 
      FileOutputStream(entry.getName());
    dest = new BufferedOutputStream(fos, BUFFER);
    while ((count = is.read(data, 0, BUFFER)) != -1) {
       dest.write(data, 0, count);
    }
    
  5. Finally, close all input and output streams:
    dest.flush();
    dest.close();
    is.close();
    

The complete source program is shown in Code Sample 2. Again, to test this class, compile it and run it by passing a file in a ZIP format as an argument:

prompt> java UnZip2 somefile.zip

Code Sample 2: UnZip2.java

import java.io.*;
import java.util.*;
import java.util.zip.*;

public class UnZip2 {
   static final int BUFFER = 2048;
   public static void main (String argv[]) {
      try {
         BufferedOutputStream dest = null;
         BufferedInputStream is = null;
         ZipEntry entry;
         ZipFile zipfile = new ZipFile(argv[0]);
         Enumeration e = zipfile.entries();
         while(e.hasMoreElements()) {
            entry = (ZipEntry) e.nextElement();
            System.out.println("Extracting: " +entry);
            is = new BufferedInputStream
              (zipfile.getInputStream(entry));
            int count;
            byte data[] = new byte[BUFFER];
            FileOutputStream fos = new 
              FileOutputStream(entry.getName());
            dest = new 
              BufferedOutputStream(fos, BUFFER);
            while ((count = is.read(data, 0, BUFFER)) 
              != -1) {
               dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
            is.close();
         }
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

Compressing and Archiving Data in a ZIP File

The ZipOutputStream can be used to compress data to a ZIP file. The ZipOutputStream writes data to an output stream in a ZIP format. There are a number of steps involved in creating a ZIP file.

  1. The first step is to create a ZipOutputStream object, to which we pass the output stream of the file we wish to write to. Here is how you create a ZIP file entitled "myfigs.zip":
    FileOutputStream dest = new 
      FileOutputStream("myfigs.zip");
    ZipOutputStream out = new 
      ZipOutputStream(new BufferedOutputStream(dest));
    
  2. Once the target zip output stream is created, the next step is to open the source data file. In this example, source data files are those files in the current directory. The list command is used to get a list of files in the current directory:
    File f = new File(".");
    String files[] = f.list();
    for (int i=0; i<files.length; i++) {
       System.out.println("Adding: "+files[i]);
       FileInputStream fi = new FileInputStream(files[i]);
       // create zip entry
       // add entries to ZIP file
    }
    


    Note: This code sample is capable of compressing all files in the current directory. It doesn't handle subdirectories. As an exercise, you may want to modify Code Sample 3 to handle subdirectories.


  3. Create a zip entry for each file that is read:

    ZipEntry entry = new ZipEntry(files[i]))

  4. Before you can write data to the ZIP output stream, you must first put the zip entry object using the putNextEntry method:

    out.putNextEntry(entry);

  5. Write the data to the ZIP file:
    int count;
    while((count = origin.read(data, 0, BUFFER)) != -1) {
       out.write(data, 0, count);
    }
    
  6. Finally, you close the input and output streams:
    origin.close();
    out.close();
    

The complete source program is shown in Code Sample 3.

Code Sample 3: Zip.java

import java.io.*;
import java.util.zip.*;

public class Zip {
   static final int BUFFER = 2048;
   public static void main (String argv[]) {
      try {
         BufferedInputStream origin = null;
         FileOutputStream dest = new 
           FileOutputStream("c://zip//myfigs.zip");
         ZipOutputStream out = new ZipOutputStream(new 
           BufferedOutputStream(dest));
         //out.setMethod(ZipOutputStream.DEFLATED);
         byte data[] = new byte[BUFFER];
         // get a list of files from current directory
         File f = new File(".");
         String files[] = f.list();

         for (int i=0; i<files.length; i++) {
            System.out.println("Adding: "+files[i]);
            FileInputStream fi = new 
              FileInputStream(files[i]);
            origin = new 
              BufferedInputStream(fi, BUFFER);
            ZipEntry entry = new ZipEntry(files[i]);
            out.putNextEntry(entry);
            int count;
            while((count = origin.read(data, 0, 
              BUFFER)) != -1) {
               out.write(data, 0, count);
            }
            origin.close();
         }
         out.close();
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}


Note: Entries can be added to a ZIP file either in a compressed (DEFLATED) or uncompressed (STORED) form. The setMethod can be used to set the method of storage. For example, to set the method to DEFLATED (compressed) use: out.setMethod(ZipOutputStream.DEFLATED) and to set it to STORED (not compressed) use: out.setMethod(ZipOutputStream.STORED).

ZIP File Properties

The ZipEntry class describes a compressed file stored in a ZIP file. The various methods contained in this class can be used to set and get pieces of information about the entry. The ZipEntry class is used by the ZipFile and ZipInputStream to read ZIP files, and the ZipOutputStream to write ZIP files. Some of the most useful methods available in the ZipEntry class are shown, along with a description, in Table 2.

Table 2: Some useful methods from the ZipEntry class

Method SignatureDescription
public String getComment()Returns the comment string for the entry, null if none
public long getCompressedSize()Returns the compressed size of the entry, -1 if not known
public int getMethod()Returns the compression method of the entry, -1 if not specified
public String getName()Returns the name of the entry
public long getSize()Returns the uncompressed zip of the entry, -1 if unknown
public long getTime()Returns the modification time of the entry, -1 if not specified
public void setComment(String c)Sets the optional comment string for the entry
public void setMethod(int method)Sets the compression method for the entry
public void setSize(long size)Sets the uncompressed size of the entry
public void setTime(long time)Sets the modification time of the entry
Checksums

Some of the other important classes in the java.util.zip package are the Adler32 and CRC32 classes, which implement the java.util.zip.Checksum interface and compute the checksums required for data compression. The Adler32 algorithm is known to be faster than the CRC32 and it is as reliable. The getValue method can be used to obtain the current value of the checksum. The reset method can be used to reset the checksum to its default value.

Checksums can be used to mask corrupted files or messages. For example, suppose you want to create a ZIP file then transfer it to a remote machine. Once it is at the remote machine, using the checksum you can check whether the file got corrupted during the transmission. To demonstrate how to create checksums, we modify Code Sample 1 and Code Sample 3 to use CheckedInputStream and CheckedOutputStream as shown in Code Sample 4 and Code Sample 5.

Code Sample 4: Zip.java

import java.io.*;
import java.util.zip.*;

public class Zip {
   static final int BUFFER = 2048;
   public static void main (String argv[]) {
      try {
         BufferedInputStream origin = null;
         FileOutputStream dest = new 
           FileOutputStream("c://zip//myfigs.zip");
         CheckedOutputStream checksum = new 
           CheckedOutputStream(dest, new Adler32());
         ZipOutputStream out = new 
           ZipOutputStream(new 
             BufferedOutputStream(checksum));
         //out.setMethod(ZipOutputStream.DEFLATED);
         byte data[] = new byte[BUFFER];
         // get a list of files from current directory
         File f = new File(".");
         String files[] = f.list();

         for (int i=0; i<files.length; i++) {
            System.out.println("Adding: "+files[i]);
            FileInputStream fi = new 
              FileInputStream(files[i]);
            origin = new 
              BufferedInputStream(fi, BUFFER);
            ZipEntry entry = new ZipEntry(files[i]);
            out.putNextEntry(entry);
            int count;
            while((count = origin.read(data, 0, 
              BUFFER)) != -1) {
               out.write(data, 0, count);
            }
            origin.close();
         }
         out.close();
         System.out.println("checksum: 
           "+checksum.getChecksum().getValue());
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

Code Sample 5: UnZip.java

import java.io.*;
import java.util.zip.*;

public class UnZip {
   public static void main (String argv[]) {
      try {
         final int BUFFER = 2048;
         BufferedOutputStream dest = null;
         FileInputStream fis = new 
	   FileInputStream(argv[0]);
         CheckedInputStream checksum = new 
           CheckedInputStream(fis, new Adler32());
         ZipInputStream zis = new 
           ZipInputStream(new 
             BufferedInputStream(checksum));
         ZipEntry entry;
         while((entry = zis.getNextEntry()) != null) {
            System.out.println("Extracting: " +entry);
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            FileOutputStream fos = new 
              FileOutputStream(entry.getName());
            dest = new BufferedOutputStream(fos, 
              BUFFER);
            while ((count = zis.read(data, 0, 
              BUFFER)) != -1) {
               dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
         }
         zis.close();
         System.out.println("Checksum: 
           "+checksum.getChecksum().getValue());
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

To test Code Sample 4 and 5, compile the classes and then run the Zip class to create a ZIP archive (a checksum value will be calculated and printed on the screen for your information) and then run the UnZip class to decompress the archive (a checksum value will be printed on the console). The two values must be exactly the same, otherwise the file is corrupted. Checksums are very useful in validating data. For example, you can create a ZIP file and send it to your friend along with a checksum. Your friend unzips the file and compares the checksum with the one you provided, if they are the same your friend knows that the file is authentic.

Compressing Objects

We have seen how to compress data available in file form and add it to an archive. But what if the data you wish to compress is not available in a file? Assume for example, that you are transferring large objects over sockets. To improve the performance of your application, you may want to compress the objects before sending them across the network and uncompress them at the destination. As another example, let's say you want to save objects on the disk in compressed format. The ZIP format, which is record-based, is not really suitable for this job. The GZIP is more appropriate as it operates on a single stream of data.

Now, let's see an example of how to compress objects before writing them on disk and how to decompress them after reading them from the disk. Code Sample 6 is a simple class that implements the Serializable interface to signal the JVM1 that we wish to serialize instances of this class.

Code Sample 6: Employee.java

import java.io.*;

public class Employee implements Serializable {
   String name;
   int age;
   int salary;

   public Employee(String name, int age, int salary) {
      this.name = name;
      this.age = age;
      this.salary = salary;
   }

   public void print() {
      System.out.println("Record for: "+name);
      System.out.println("Name: "+name);
      System.out.println("Age: "+age);
      System.out.println("Salary: "+salary);
  }
}

Now, write another class that creates a couple of objects from the Employee class. Code Sample 7 creates two objects (sarah and sam) of the Employee class, then saves their state in a file in a compressed format.

Code Sample 7 SaveEmployee.java

import java.io.*;
import java.util.zip.*;

public class SaveEmployee {
   public static void main(String argv[]) throws 
     Exception {
      // create some objects
      Employee sarah = new Employee("S. Jordan", 28, 
        56000);
      Employee sam = new Employee("S. McDonald", 29, 
        58000);
      // serialize the objects sarah and sam
      FileOutputStream fos = new 
        FileOutputStream("db");
      GZIPOutputStream gz = new GZIPOutputStream(fos);
      ObjectOutputStream oos = new 
        ObjectOutputStream(gz);
      oos.writeObject(sarah);
      oos.writeObject(sam);
      oos.flush();
      oos.close();
      fos.close();
   }
}

Now, the ReadEmployee class shown in Code Sample 8 is used to reconstruct the state of the two objects. Once the state has been constructed the print method is invoked on them.

Code Sample 8: ReadEmployee.java

import java.io.*;
import java.util.zip.*;

public class ReadEmployee {
   public static void main(String argv[]) throws 
     Exception{
      //deserialize objects sarah and sam
      FileInputStream fis = new FileInputStream("db");
      GZIPInputStream gs = new GZIPInputStream(fis);
      ObjectInputStream ois = new ObjectInputStream(gs);
      Employee sarah = (Employee) ois.readObject();
      Employee sam = (Employee) ois.readObject();
      //print the records after reconstruction of state
      sarah.print();
      sam.print();
      ois.close();
      fis.close();
   }
}

The same idea can be used to compress large objects that are sent over sockets. The following segment of code show how to write objects in a compressed format, from the server to the client:

// write to client
GZIPOutputStream gzipout = new 
  GZIPOutputStream(socket.getOutputStream());
ObjectOutputStream oos = new 
  ObjectOutputStream(gzipout);
oos.writeObject(obj);
gzipos.finish();

And, the following segment of code shows how to decompress the objects at the client side once received from the server:

// read from server
Socket socket = new Socket(remoteServerIP, PORT);
GZIPInputStream gzipin = new 
  GZIPInputStream(socket.getInputStream());
ObjectInputStream ois = new ObjectInputStream(gzipin);
Object o = ois.readObject();
What about JAR Files?

The Java ARchive (JAR) format is based on the standard ZIP file format with an optional manifest file. If you wish to create JAR files or extract files from a JAR file from within your Java applications, use the java.util.jar package, which provides classes for reading and writing JAR files. Using the classes provided by the java.util.jar package is very similar to using the classes provided by the java.util.zip package as described in this article. Therefore, you should be able to adapt much of the code in this article if you wish to use the java.util.jar package.

Conclusion

This article discussed the APIs that you can use to compress and decompress data from within your applications, with code samples throughout the article to show how to use the java.util.zip package to compress and decompress data. Now you have the tools to utilize data compression and decompression in your applications.

The article also shows how to compress and decompress data on the fly in order to reduce network traffic and improve the performance of your client/server applications. Compressing data on the fly, however, improves the performance of client/server applications only when the objects being compressed are more than a couple of hundred bytes. You would not be able to observe improvement in performance if the objects being compressed and transferred are simple String objects, for example.

For more information

Coffecup Logo

About the Author

Qusay H. Mahmoud provides Java consulting and training services. He has published dozens of articles on Java, and is the author of Distributed Programming with Java (Manning Publications, 1999) and Learning Wireless Java (O'Reilly, 2002).  

告别命令行恐惧!用nTopology可视化工具5分钟搞定三维Voronoi泡沫建模 本文介绍如何利用nTopology可视化工具快速生成三维Voronoi泡沫结构,无需编程即可完成复杂建模。Voronoi结构在轻量化设计、能量吸收和生物医学等领域具有重要应用,传统命令行方法门槛较高。通过nTopology的四步流程,用户可在5分钟内创建仿真就绪模型,大幅提升设计效率。 阅读详情

相关推荐

鸿蒙系统下基于WebRTC的高效音视频通话开发实战

本文详细介绍了在鸿蒙系统下集成WebRTC技术实现高效音视频通话的实战开发。通过分析鸿蒙分布式软总线与WebRTC低延迟特性的结合优势,提供了从环境搭建、NAPI桥接层开发到音视频采集、P2P连接建立与渲染的完整流程。文章重点探讨了如何利用鸿蒙特性进行性能优化,包括网络自适应、抗抖动策略及系统级调优,旨在帮助开发者构建稳定、低延迟的实时通信应用。

night的博客 573

TrueLicense源码解析-寻找docker中使用license安装后存放的位置

springBoot调用TrueLicense生成证书,根据源码寻找证书安装文件位置,Windows操作系统

MyfishCake的博客 2049

无人机蜂群联合指挥作战技术详解

随着人工智能、通信技术、新材料等领域的不断进步,无人机蜂群联合指挥作战技术将迎来更加广阔的发展前景。未来,无人机蜂群将更加智能化、自主化,能够执行更加复杂、精细的作战任务。同时,加强国际合作,共同制定国际规则和标准,将是推动无人机蜂群技术健康发展的重要方向。无人机蜂群技术,是指通过先进的通信技术、自主导航与决策算法,将大量小型、低成本、功能各异的无人机组织成一个高度协同的群体,执行复杂多样的军事任务。2. 通信与数据链:采用高速、低延迟、抗干扰的通信技术,保障群体内无人机间的信息交换。

专注多旋翼、复合翼无人机技术研究,从事低空经济行业。 1546

SM4加解密

基于开源项目:https://github.com/ZZMarquis/gmhelper @Test public void test(){ String str = "adf4976d917a07e0513dce45b6981919"; String miwei = "{\"你好\":\"2020\"}"; String abc = ""; byte[] cipherText = null; byte[] decr

c1052981766的专栏 4038

Starlink第三代终端和第二代终端的差异性有哪些?

starlink第三代终端和第二代终端的额差异

chen2jiang3的博客 2933

让 ABAP 内表真正释放内存:从 CLEAR、FREE 到打破 Table Sharing 的实战技巧

ABAP内表内存管理的关键在于理解其运行时结构:DELETE操作仅逻辑删除行而不会释放内存,CLEAR或FREE才能真正回收内存。常见的误区包括误判空表状态和忽视内表共享机制。实际应用中,大表筛选后应采用VALUE表达式或逐行插入方式重建表体以释放内存。典型案例显示,正确处理内表内存可显著降低SAP Gateway和批处理程序的内存消耗,提升系统稳定性。开发时需结合调试工具观察内存状态,避免因共享机制导致无效回收。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 325

记一次编码转换,遇到的坑

记一次编码转换,遇到的坑 场景: 爬虫,爬取需要下载的文件,如img,excel,这时我们需要response.content,获取二进制数据,因某些原因,没有进行先下现存,需要保持二进制数据到数据库,然后取出数据库的数据,进行解析 数据库: mongodb kafka mongodb可以正常存储二进制数据 但是kafka存储过程报错,因kafka 存储需要json序列化一下(目前我用的这种方式,kafka小白)进行存储,此时报错,json.loads,无法序列化二进制文件,...

yangqingbin_666的博客 973

【openGauss实战1】openGauss基于CentOS8的部署

基于openGauss数据库在CentOS8上的安装实践。

IT邦德 3053

Exception in thread “main“ java.lang.IllegalArgumentException: Incorrect length for hybrid encoding

Exception in thread "main" java.lang.IllegalArgumentException: Incorrect length for hybrid encoding at org.bouncycastle.math.ec.ECCurve.decodePoint(ECCurve.java:428) at com.qz.tms.face.util.SM2Util.verify(SM2Util.java:177) at com.qz.tms.face.util.SM2Uti

我不是程序员的博客 577

SAP HANA 中的 Union Node Pruning:让 Calculation View 少走弯路的关键优化

摘要:SAP HANA的Union Node Pruning技术通过在执行前排除无关数据源来优化查询性能。该技术主要采用三种方式:Constant Mapping(适用于规则稳定的场景)、Pruning Configuration Table(灵活性高)和Column-Based Pruning(基于列可用性)。典型应用场景包括分层存储的数据查询,如区分当前和历史销售数据。需要注意的是,当查询发生Unfolding且不含聚合时,Pruning可能失效,此时可通过NO_CALC_VIEW_UNFOLDING提

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 875

微信小程序 - 微信支付报错 “调用支付JSAPI缺少参数: total_fee“,微信小程序强力解决调用支付JSAPI缺少参数:total_fee解决办法(包括微信小程序云开发对接微信支付报错问题)

调用支付jsapi缺少参数 total_fee,微信小程序拉起支付报: 调用支付JSAPI缺少参数: total_fee,微信小程序云开发支付 调用支付jsapi缺少参数:total_fee,微信小程序云开发微信支付报错,拉起支付失败,调用支付jsapi缺少参数:total_fee_小程序支付问题怎么解决?使用微信小程序云开发对接微信支付,拷贝官方的示例代码运行,详细解决方案,如何解决这个情况,后端没问题,还是依旧报错,微信小程序 微信支付 total_fee 缺失参数 云开发 统一下单 JSAPI,报错:

🏆 前端领域优质创作者 2961

java.io.WinNTFileSystem

Unicode-aware FileSystem for Windows NT/2000. Since:1.4Author:Konstantin Kladko 转载于:https://www.cnblogs.com/rongyao/p/9338889.html

weixin_30556959的博客 292

AIPex:AI + 自然语言驱动的浏览器自动化扩展

AIPex是一款革命性的Chrome扩展,通过AI技术实现自然语言驱动的浏览器自动化。它支持30多种自动化工具,包括智能标签页管理(分组、切换、批量操作)、页面内容提取(文本、链接、元数据)、交互元素操作(点击、滚动)以及表单智能填写等功能。用户只需用自然语言下达指令,即可快速完成复杂的浏览器操作,大幅提升工作效率。AIPex特别适合需要处理大量重复性网页操作的用户,如数据分析师、产品经理等。

blues_C的博客 1141

Compressing and Decompressing Data using JavaTM APIs (转)

Compressing and Decompressing Data using JavaTM APIs (转)[@more@]Compressing and Decompressing Data using JavaTM ap...

csd3176的博客 225

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

iobject java,执行iobject java 时报错

java.lang.UnsatisfiedLinkError: F:\A_supermap\superMap_file\SMO_Java_811_14428_59859_Win_vc11_CHS_Zip\Bin\WrapjGeo.dll: Can't load IA 32-bit .dll on a AMD 64-bit platformat java.lang.ClassLoader$Nativ...

weixin_42116596的博客 322

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

zip压缩以及解压 Compressing and Decompressing Data Using Java APIs

<br />from(http://java.sun.com/developer/technicalArticles/Programming/compression/)<br /> <br />by Qusay H. Mahmoud <br />with contributions from Konstantin Kladko<br />February 2002<br /> <br />Many sources of information contain redundant data or data t

zhjp4295216的专栏 883

java的方法decompress_Java LZ4SafeDecompressor.decompress方法代码示例

import net.jpountz.lz4.LZ4SafeDecompressor; //导入方法依赖的package包/类public static void main(String[] args) throws IOException {LZ4Factory factory = LZ4Factory.fastestInstance();byte[] data = "Compressors a...

weixin_31999597的博客 830

java zip解压_Java zip解压及读取

importcom.alibaba.fastjson.JSONObject;import java.io.*;importjava.util.ArrayList;importjava.util.Enumeration;importjava.util.List;importjava.util.zip.ZipEntry;importjava.util.zip.ZipFile;public classD...

weixin_39942488的博客 217

SpringBoot启动遇到的异常问题

1、 问题 SpringBoot本身需要引入自身的一个parent,但是pom里面一般都已经存在了一个parent,这时就不能在引入springBoot的parent 解决方案:             org.springframework.boot             spring-boot-starter-web             1.3.3.RELEASE

Emine 7万+

idea编译时报错“常量字符串过长”

依次点击File >> Settings >> Build,Execution,Deployment >> Compiler >>Java Compiler 将Use compiler改为eclipse 如果改完后build报错 Error:java: Internal error: java.lang.IllegalArgumentException at org.eclipse.jdt.internal.compiler.tool...

I'm your wrong princess 1177

打包Zip文件下载

项目里要把当个文件单个打包下载,找了个资料,备份 public synchronized static ByteArrayOutputStream zip(Map&lt;String, byte[]&gt; map) throws IOException { ByteArrayOutputStream baos = new ByteArra...

幽空命记 192

Python安装常见问题(1):zipimport.ZipImportError: can't decompress data

在CentOS以及其他的Linux系统中遇到安装包安装错误的原因,大多数都是因为缺少依赖包导致的,所以对于错误:zipimport.ZipImportError: can’t decompress data,是因为缺少zlib 的相关工具包导致的,知道了问题所在,那么我们只需要安装相关依赖包即可, 1、打开终端,输入一下命令安装zlib相关依赖包: yum -y install zli

架构师之路 11万+

JAVA TEST 1

1. What is Java?Why was the Java programming language created?*C. Java was created to produce applications for smallappliances.(1995年Java衍生自smalltalk最初设计应用于电视机顶盒的嵌入式系统,而后在网络层内意外的大获成就)<br /> Which of the following programming paradigmsallows a programmer to

Chatopera 1万+

java object... 出错,iobject java 打开数据源,出错

前两天运行都好好的,今天运行就出错了,啥原因呢?代码:DatasourceConnectionInfo dci = new DatasourceConnectionInfo();dci.setEngineType(EngineType.MYSQL);dci.setServer("127.0.0.1");dci.setDatabase("ns");dci.setUser("root");dci.se...

weixin_36225637的博客 350

The Science of JavaTM Sound Technology

  The Science of JavaTM Sound TechnologyBy Michael D. Meloan(June 1999) Sound creates mood, triggers memories, and in conjunction with visual imagery weaves whole worlds of fantasy. Sound is t

CanFly的专栏 2653
上一篇: Distributed Java Programming with RMI and CORBA
下一篇: Utilizing the Map Interface from the Collections Framework
CanFly
博客等级 码龄25年 0粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值