The code dynamically creates a file name which sometimes exceed the specified 255 characters length for the file name. So it needs to be cropped into a unique short length string in Java. Below are the restrictions:
- The shortened string will be used as a file name
- The reverse mechanism of getting back the original file name from the compressed file name should also work
- The compression/decompression will be done on-the-fly. ie., they should be done everytime the file is saved or retrieved.
Tried approaches:
- Use the UUID class to generate unique identifier. But it fails the 2nd condition above - unable to get the original string from the UUID
- Inflater/Deflater, Inflater/Deflater Streams, GZIP Streams - The compressed string contains many junk characters which cannot be used as a file name. Also not sure about the uniqueness of the string
Please suggest the best approach for this problem
Update: The solutions from the question marked as duplicate gives strings which has characters which cannot be used as a file name or bit streams. They do not give solution to the actual problem