@Test public void testgetSafeFileAndFolderName () { assertNull (AS2IOHelper.getSafeFileAndFolderName (null)); assertEquals ("", AS2IOHelper.getSafeFileAndFolderName ("")); assertEquals ("abc", AS2IOHelper.getSafeFileAndFolderName ("abc")); assertEquals ("abc/def", AS2IOHelper.getSafeFileAndFolderName ("abc/def")); assertEquals ("abc/def", AS2IOHelper.getSafeFileAndFolderName ("abc\\def")); assertEquals ("abc/def/blub", AS2IOHelper.getSafeFileAndFolderName ("abc/def\\blub")); assertEquals ("abc_/d_ef/g_hi", AS2IOHelper.getSafeFileAndFolderName ("abc</d|ef\\g*hi")); assertEquals ("/abc", AS2IOHelper.getSafeFileAndFolderName ("/abc")); assertEquals ("/abc", AS2IOHelper.getSafeFileAndFolderName ("\\abc")); assertEquals ("abc", AS2IOHelper.getSafeFileAndFolderName ("abc/")); assertEquals ("abc", AS2IOHelper.getSafeFileAndFolderName ("abc\\")); assertEquals ("/abc", AS2IOHelper.getSafeFileAndFolderName ("/abc/")); assertEquals ("/abc", AS2IOHelper.getSafeFileAndFolderName ("/abc\\")); assertEquals ("/abc", AS2IOHelper.getSafeFileAndFolderName ("\\abc/")); assertEquals ("/abc", AS2IOHelper.getSafeFileAndFolderName ("\\abc\\")); assertEquals ("z:/abc", AS2IOHelper.getSafeFileAndFolderName ("z:\\abc\\")); assertEquals ("z:/abc/test.txt", AS2IOHelper.getSafeFileAndFolderName ("z:\\abc/test.txt")); assertEquals ("z:/a_bc/tes_t.txt", AS2IOHelper.getSafeFileAndFolderName ("z:\\a*bc/tesät.txt")); assertEquals ("z:/com1", AS2IOHelper.getSafeFileAndFolderName ("z:\\com1")); assertEquals ("z:/_com2", AS2IOHelper.getSafeFileAndFolderName ("z:\\com2")); }
@Nullable public static String getSafeFileAndFolderName (@Nullable final String s) { if (StringHelper.hasNoText (s)) return s; final File aBase = new File (FilenameHelper.getPathUsingUnixSeparator (s)); final StringBuilder aSB = new StringBuilder (); File f = aBase; while (f != null) { final String sName = f.getName (); if (sName.length () == 0) { aSB.insert (0, FilenameHelper.getPathUsingUnixSeparator (f.getPath ())); } else { final String sSecuredName = FilenameHelper.getAsSecureValidASCIIFilename (sName); aSB.insert (0, StringHelper.getNotNull (sSecuredName, "") + FilenameHelper.UNIX_SEPARATOR); } f = f.getParentFile (); } return aSB.deleteCharAt (aSB.length () - 1).toString (); }
AS2IOHelper { @Nullable public static String getSafeFileAndFolderName (@Nullable final String s) { if (StringHelper.hasNoText (s)) return s; final File aBase = new File (FilenameHelper.getPathUsingUnixSeparator (s)); final StringBuilder aSB = new StringBuilder (); File f = aBase; while (f != null) { final String sName = f.getName (); if (sName.length () == 0) { aSB.insert (0, FilenameHelper.getPathUsingUnixSeparator (f.getPath ())); } else { final String sSecuredName = FilenameHelper.getAsSecureValidASCIIFilename (sName); aSB.insert (0, StringHelper.getNotNull (sSecuredName, "") + FilenameHelper.UNIX_SEPARATOR); } f = f.getParentFile (); } return aSB.deleteCharAt (aSB.length () - 1).toString (); } }
AS2IOHelper { @Nullable public static String getSafeFileAndFolderName (@Nullable final String s) { if (StringHelper.hasNoText (s)) return s; final File aBase = new File (FilenameHelper.getPathUsingUnixSeparator (s)); final StringBuilder aSB = new StringBuilder (); File f = aBase; while (f != null) { final String sName = f.getName (); if (sName.length () == 0) { aSB.insert (0, FilenameHelper.getPathUsingUnixSeparator (f.getPath ())); } else { final String sSecuredName = FilenameHelper.getAsSecureValidASCIIFilename (sName); aSB.insert (0, StringHelper.getNotNull (sSecuredName, "") + FilenameHelper.UNIX_SEPARATOR); } f = f.getParentFile (); } return aSB.deleteCharAt (aSB.length () - 1).toString (); } private  AS2IOHelper(); }
AS2IOHelper { @Nullable public static String getSafeFileAndFolderName (@Nullable final String s) { if (StringHelper.hasNoText (s)) return s; final File aBase = new File (FilenameHelper.getPathUsingUnixSeparator (s)); final StringBuilder aSB = new StringBuilder (); File f = aBase; while (f != null) { final String sName = f.getName (); if (sName.length () == 0) { aSB.insert (0, FilenameHelper.getPathUsingUnixSeparator (f.getPath ())); } else { final String sSecuredName = FilenameHelper.getAsSecureValidASCIIFilename (sName); aSB.insert (0, StringHelper.getNotNull (sSecuredName, "") + FilenameHelper.UNIX_SEPARATOR); } f = f.getParentFile (); } return aSB.deleteCharAt (aSB.length () - 1).toString (); } private  AS2IOHelper(); @Nonnull static FileOperationManager getFileOperationManager(); @Nonnull static File getDirectoryFile(@Nonnull final String sDirectory); @Nonnull @Nonempty static String getTransferRate(final long nBytes, @Nonnull final StopWatch aSW); @Nonnull static File getUniqueFile(@Nonnull final File aDir, @Nullable final String sFilename); static void handleError(@Nonnull final File aFile, @Nonnull final String sErrorDirectory); @Nonnull static File moveFile(@Nonnull final File aSrc,
                               @Nonnull final File aDestFile,
                               final boolean bOverwrite,
                               final boolean bRename); @Nullable static String getFilenameFromMessageID(@Nonnull final String sMessageID); @Nullable static String getSafeFileAndFolderName(@Nullable final String s); @Nonnull @ReturnsMutableCopy static byte [] getAllAsciiBytes(@Nonnull final String sString); @Nonnull static OutputStream getContentTransferEncodingAwareOutputStream(@Nonnull final OutputStream aOS,
                                                                          @Nullable final String sEncoding); @Nonnull static InputStream getContentTransferEncodingAwareInputStream(@Nonnull final InputStream aIS,
                                                                        @Nullable final String sEncoding); }
AS2IOHelper { @Nullable public static String getSafeFileAndFolderName (@Nullable final String s) { if (StringHelper.hasNoText (s)) return s; final File aBase = new File (FilenameHelper.getPathUsingUnixSeparator (s)); final StringBuilder aSB = new StringBuilder (); File f = aBase; while (f != null) { final String sName = f.getName (); if (sName.length () == 0) { aSB.insert (0, FilenameHelper.getPathUsingUnixSeparator (f.getPath ())); } else { final String sSecuredName = FilenameHelper.getAsSecureValidASCIIFilename (sName); aSB.insert (0, StringHelper.getNotNull (sSecuredName, "") + FilenameHelper.UNIX_SEPARATOR); } f = f.getParentFile (); } return aSB.deleteCharAt (aSB.length () - 1).toString (); } private  AS2IOHelper(); @Nonnull static FileOperationManager getFileOperationManager(); @Nonnull static File getDirectoryFile(@Nonnull final String sDirectory); @Nonnull @Nonempty static String getTransferRate(final long nBytes, @Nonnull final StopWatch aSW); @Nonnull static File getUniqueFile(@Nonnull final File aDir, @Nullable final String sFilename); static void handleError(@Nonnull final File aFile, @Nonnull final String sErrorDirectory); @Nonnull static File moveFile(@Nonnull final File aSrc,
                               @Nonnull final File aDestFile,
                               final boolean bOverwrite,
                               final boolean bRename); @Nullable static String getFilenameFromMessageID(@Nonnull final String sMessageID); @Nullable static String getSafeFileAndFolderName(@Nullable final String s); @Nonnull @ReturnsMutableCopy static byte [] getAllAsciiBytes(@Nonnull final String sString); @Nonnull static OutputStream getContentTransferEncodingAwareOutputStream(@Nonnull final OutputStream aOS,
                                                                          @Nullable final String sEncoding); @Nonnull static InputStream getContentTransferEncodingAwareInputStream(@Nonnull final InputStream aIS,
                                                                        @Nullable final String sEncoding);  }