Java Code Examples for java.nio.charset.Charset#aliases()

The following examples show how to use java.nio.charset.Charset#aliases() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: p4ic4idea   File: InferFileTypeTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test printout the JVM's supported charsets.
 */
@Test
public void testPrintoutSupportedCharsets() {
    SortedMap<String, Charset> charsetMap = Charset.availableCharsets();
    debugPrint("------------- availableCharsets ----------------");
    for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
        String canonicalCharsetName = entry.getKey();
        debugPrint(canonicalCharsetName);
        Charset charset = entry.getValue();
        Set<String> aliases = charset.aliases();
        for (String alias : aliases) {
            debugPrint("\t" + alias);
        }
    }
    debugPrint("-----------------------------------------");
    String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
    debugPrint("------------- perforceCharsets ----------------");
    for (String perforceCharset : perforceCharsets) {
        debugPrint(perforceCharset + " ... "
                + PerforceCharsets.getJavaCharsetName(perforceCharset));
    }
    debugPrint("-----------------------------------------");
    debugPrint("-----------------------------------------");
    debugPrint("Charset.defaultCharset().name(): " + Charset.defaultCharset().name());
    debugPrint("-----------------------------------------");
}
 
Example 2
Source Project: p4ic4idea   File: InferFileTypeTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test printout the JVM's supported charsets.
 */
@Test
public void testPrintoutSupportedCharsets() {
    SortedMap<String, Charset> charsetMap = Charset.availableCharsets();
    debugPrint("------------- availableCharsets ----------------");
    for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
        String canonicalCharsetName = entry.getKey();
        debugPrint(canonicalCharsetName);
        Charset charset = entry.getValue();
        Set<String> aliases = charset.aliases();
        for (String alias : aliases) {
            debugPrint("\t" + alias);
        }
    }
    debugPrint("-----------------------------------------");
    String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
    debugPrint("------------- perforceCharsets ----------------");
    for (String perforceCharset : perforceCharsets) {
        debugPrint(perforceCharset + " ... "
                + PerforceCharsets.getJavaCharsetName(perforceCharset));
    }
    debugPrint("-----------------------------------------");
    debugPrint("-----------------------------------------");
    debugPrint("Charset.defaultCharset().name(): " + Charset.defaultCharset().name());
    debugPrint("-----------------------------------------");
}
 
Example 3
private void registerJavaMappingForEncodingDefinition(EncodingDefinition encodingDefinition) {
    final Charset charset = encodingDefinition.getJavaCharset();
    if (encodingDefinition.isInformationOnly() || encodingDefinition.isFirebirdOnly() || charset == null) {
        return;
    }
    final EncodingDefinition currentEncodingDefinition = javaCharsetToDefinition.get(charset);
    if (currentEncodingDefinition == null) {
        // Map Java charset to EncodingDefinition
        javaCharsetToDefinition.put(charset, encodingDefinition);
        javaAliasesToDefinition.put(charset.name().toLowerCase(), encodingDefinition);
        for (String charsetAlias : charset.aliases()) {
            javaAliasesToDefinition.put(charsetAlias.toLowerCase(), encodingDefinition);
        }
    } else if (log.isDebugEnabled()) {
        log.debug(String.format(
                "Not mapping java charset %s to Firebird encoding %s, already mapped to Firebird encoding %s",
                charset.name(), encodingDefinition.getEncoding(),
                currentEncodingDefinition.getFirebirdEncodingName()));
    }
}
 
Example 4
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings, ServerVersion minimumVersion) {
    this.charsetName = charsetName;
    this.mblen = mblen;
    this.priority = priority;

    for (int i = 0; i < javaEncodings.length; i++) {
        String encoding = javaEncodings[i];
        try {
            Charset cs = Charset.forName(encoding);
            addEncodingMapping(cs.name());

            Set<String> als = cs.aliases();
            Iterator<String> ali = als.iterator();
            while (ali.hasNext()) {
                addEncodingMapping(ali.next());
            }
        } catch (Exception e) {
            // if there is no support of this charset in JVM it's still possible to use our converter for 1-byte charsets
            if (mblen == 1) {
                addEncodingMapping(encoding);
            }
        }
    }

    if (this.javaEncodingsUc.size() == 0) {
        if (mblen > 1) {
            addEncodingMapping("UTF-8");
        } else {
            addEncodingMapping("Cp1252");
        }
    }

    this.minimumVersion = minimumVersion;
}
 
Example 5
Source Project: r-course   File: CharsetMapping.java    License: MIT License 5 votes vote down vote up
/**
 * Constructs MysqlCharset object
 * 
 * @param charsetName
 *            MySQL charset name
 * @param mblen
 *            Max number of bytes per character
 * @param priority
 *            MysqlCharset with highest lever of this param will be used for Java encoding --> Mysql charsets conversion.
 * @param javaEncodings
 *            List of Java encodings corresponding to this MySQL charset; the first name in list is the default for mysql --> java data conversion
 */
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings) {
    this.charsetName = charsetName;
    this.mblen = mblen;
    this.priority = priority;

    for (int i = 0; i < javaEncodings.length; i++) {
        String encoding = javaEncodings[i];
        try {
            Charset cs = Charset.forName(encoding);
            addEncodingMapping(cs.name());

            Set<String> als = cs.aliases();
            Iterator<String> ali = als.iterator();
            while (ali.hasNext()) {
                addEncodingMapping(ali.next());
            }
        } catch (Exception e) {
            // if there is no support of this charset in JVM it's still possible to use our converter for 1-byte charsets
            if (mblen == 1) {
                addEncodingMapping(encoding);
            }
        }
    }

    if (this.javaEncodingsUc.size() == 0) {
        if (mblen > 1) {
            addEncodingMapping("UTF-8");
        } else {
            addEncodingMapping("Cp1252");
        }
    }
}
 
Example 6
/**
 * Constructs MysqlCharset object
 * 
 * @param charsetName
 *            MySQL charset name
 * @param mblen
 *            Max number of bytes per character
 * @param priority
 *            MysqlCharset with highest lever of this param will be used for Java encoding --> Mysql charsets conversion.
 * @param javaEncodings
 *            List of Java encodings corresponding to this MySQL charset; the first name in list is the default for mysql --> java data conversion
 */
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings) {
    this.charsetName = charsetName;
    this.mblen = mblen;
    this.priority = priority;

    for (int i = 0; i < javaEncodings.length; i++) {
        String encoding = javaEncodings[i];
        try {
            Charset cs = Charset.forName(encoding);
            addEncodingMapping(cs.name());

            Set<String> als = cs.aliases();
            Iterator<String> ali = als.iterator();
            while (ali.hasNext()) {
                addEncodingMapping(ali.next());
            }
        } catch (Exception e) {
            // if there is no support of this charset in JVM it's still possible to use our converter for 1-byte charsets
            if (mblen == 1) {
                addEncodingMapping(encoding);
            }
        }
    }

    if (this.javaEncodingsUc.size() == 0) {
        if (mblen > 1) {
            addEncodingMapping("UTF-8");
        } else {
            addEncodingMapping("Cp1252");
        }
    }
}
 
Example 7
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings, ServerVersion minimumVersion) {
    this.charsetName = charsetName;
    this.mblen = mblen;
    this.priority = priority;

    for (int i = 0; i < javaEncodings.length; i++) {
        String encoding = javaEncodings[i];
        try {
            Charset cs = Charset.forName(encoding);
            addEncodingMapping(cs.name());

            Set<String> als = cs.aliases();
            Iterator<String> ali = als.iterator();
            while (ali.hasNext()) {
                addEncodingMapping(ali.next());
            }
        } catch (Exception e) {
            // if there is no support of this charset in JVM it's still possible to use our converter for 1-byte charsets
            if (mblen == 1) {
                addEncodingMapping(encoding);
            }
        }
    }

    if (this.javaEncodingsUc.size() == 0) {
        if (mblen > 1) {
            addEncodingMapping("UTF-8");
        } else {
            addEncodingMapping("Cp1252");
        }
    }

    this.minimumVersion = minimumVersion;
}
 
Example 8
/**
 * Build up a list of all system available charsets 
 * @return hash table containing charsets names or aliases, associated to system charset 
 */
private static ConcurrentHashMap<String, String> fetchAvailableCharsets(){
	ConcurrentHashMap<String, String> charsetlist = new ConcurrentHashMap<String, String>();
    SortedMap<String, Charset> charsets = Charset.availableCharsets();
    Set<String> names = charsets.keySet();
    //if (debug>2) System.out.println("Available Charsets:");
    for (Iterator<String> e = names.iterator(); e.hasNext();) {
      String name = e.next().toLowerCase().trim();
      Charset charset = (Charset) charsets.get(name);
      if (name==null || charset== null) continue;
      name = name.trim();
      //if (debug>2) System.out.println(charset);
      charsetlist.put(name, name);
      Set<String> aliases = charset.aliases();
      
      for (Iterator<String> ee = aliases.iterator(); ee.hasNext();) {
    	  try{ 
    		  String charsetname = ee.next();
    		  if (charsetname==null || charsetname.equals("null")) continue;
    		  charsetlist.put(charsetname.toLowerCase().trim(), name);
    		  //if (debug>2) System.out.println("    " + charsetname);
    	  } catch (Exception e1){
    		  //if (debug>2) e1.printStackTrace();
    	  }
      }
    }
    return charsetlist;
  }
 
Example 9
/**
 * Test printout the JVM's supported charsets.
 */
@Test
public void testPrintoutSupportedCharsets() {
  SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

  debugPrint("------------- availableCharsets ----------------");
  for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
    String canonicalCharsetName = entry.getKey();
    debugPrint(canonicalCharsetName);
    Charset charset = entry.getValue();
    Set<String> aliases = charset.aliases();
    for (String alias : aliases) {
      debugPrint("\t" + alias);
    }
  }
  debugPrint("-----------------------------------------");

  String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
  debugPrint("------------- perforceCharsets ----------------");
  for (String perforceCharset : perforceCharsets) {
    debugPrint(perforceCharset + " ... " + PerforceCharsets.getJavaCharsetName(perforceCharset));
  }
  debugPrint("-----------------------------------------");

  debugPrint("-----------------------------------------");
  debugPrint("Charset.defaultCharset().name(): " + Charset.defaultCharset().name());
  debugPrint("-----------------------------------------");
}
 
Example 10
/**
 * Set of the charset name and aliases in lower case.
 *
 * @param charset Character set
 * @return Set of lower case names and aliases
 */
private static Set<String> toLowerCaseAliasSet(final Charset charset) {
    final Set<String> aliases = charset.aliases();
    final Set<String> potentialNames = new HashSet<>(aliases.size() + 1);
    potentialNames.add(charset.name().toLowerCase());
    for (String alias : aliases) {
        potentialNames.add(alias.toLowerCase());
    }
    return potentialNames;
}
 
Example 11
/**
 * Test printout the JVM's supported charsets.
 */
@Test
public void testPrintoutSupportedCharsets() {
  SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

  debugPrint("------------- availableCharsets ----------------");
  for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
    String canonicalCharsetName = entry.getKey();
    debugPrint(canonicalCharsetName);
    Charset charset = entry.getValue();
    Set<String> aliases = charset.aliases();
    for (String alias : aliases) {
      debugPrint("\t" + alias);
    }
  }
  debugPrint("-----------------------------------------");

  String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
  debugPrint("------------- perforceCharsets ----------------");
  for (String perforceCharset : perforceCharsets) {
    debugPrint(perforceCharset + " ... " + PerforceCharsets.getJavaCharsetName(perforceCharset));
  }
  debugPrint("-----------------------------------------");

  debugPrint("-----------------------------------------");
  debugPrint("Charset.defaultCharset().name(): " + Charset.defaultCharset().name());
  debugPrint("-----------------------------------------");
}
 
Example 12
Source Project: Tomcat8-Source-Read   File: CharsetCache.java    License: MIT License 4 votes vote down vote up
private void addToCache(String name, Charset charset) {
    cache.put(name, charset);
    for (String alias : charset.aliases()) {
        cache.put(alias.toLowerCase(Locale.ENGLISH), charset);
    }
}
 
Example 13
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWS20112Windows");
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-be/utf16-be.xbit";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}
 
Example 14
Source Project: p4ic4idea   File: SyncUtf16leFilesTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWSMac");
		assertNotNull(client);
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-le/utf16-le_test.txt";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}
 
Example 15
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWS20112Windows");
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-be/utf16-be.xbit";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}
 
Example 16
Source Project: p4ic4idea   File: SyncUtf16leFilesTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWSMac");
		assertNotNull(client);
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-le/utf16-le_test.txt";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}
 
Example 17
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWS20112Windows");
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-be/utf16-be.xbit";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}
 
Example 18
Source Project: p4ic4idea   File: SyncUtf16leFilesTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWSMac");
		assertNotNull(client);
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-le/utf16-le_test.txt";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}
 
Example 19
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWS20112Windows");
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-be/utf16-be.xbit";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}
 
Example 20
Source Project: p4ic4idea   File: SyncUtf16leFilesTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test sync utf16-le encoded files: UTF-16LE BOM: ff fe
 */
@Test
public void testSyncUtf16leFiles() {
	String depotFile = null;

	try {
		IClient client = server.getClient("p4TestUserWSMac");
		assertNotNull(client);
		server.setCurrentClient(client);
		SortedMap<String, Charset> charsetMap = Charset.availableCharsets();

		debugPrint("------------- availableCharsets ----------------");
		for (Map.Entry<String, Charset> entry : charsetMap.entrySet()) {
			String canonicalCharsetName = entry.getKey();
			debugPrint(canonicalCharsetName);
			Charset charset = entry.getValue();
			Set<String> aliases = charset.aliases();
			for (String alias : aliases) {
				debugPrint("\t" + alias);
			}
		}
		debugPrint("-----------------------------------------");

		String[] perforceCharsets = PerforceCharsets.getKnownCharsets();
		debugPrint("------------- perforceCharsets ----------------");
		for (String perforceCharset : perforceCharsets) {
			debugPrint(perforceCharset + " ... "
					+ PerforceCharsets.getJavaCharsetName(perforceCharset));
		}
		debugPrint("-----------------------------------------");

		debugPrint("-----------------------------------------");
		debugPrint("Charset.defaultCharset().name(): "
				+ Charset.defaultCharset().name());
		debugPrint("-----------------------------------------");
		
		
		depotFile = "//depot/152Bugs/utf16-le/utf16-le_test.txt";

		List<IFileSpec> files = client.sync(
				FileSpecBuilder.makeFileSpecList(depotFile),
				new SyncOptions().setForceUpdate(true));
		assertNotNull(files);

	} catch (P4JavaException e) {
		fail("Unexpected exception: " + e.getLocalizedMessage());
	}
}