Ant Java build:编译问题 - 将字符集从ISO-8859-1更改为UTF-8(Ant Java build: Compilation issue - Change of character set from ISO-8859-1 to UTF-8)
位新的字符集编码格式。 我有一个ant构建脚本,它以ISO-8859-1格式编译我的java代码。 它工作正常。
阅读了几篇文章之后: 如何在Java中转换ISO-8859-1和UTF-8?
我已经将characterSet格式更改为UTF-8,因此编译问题开始了。
抛出的错误是:
[javac] TestEncoding.java (at line 11) [javac] case '?' : [javac] ^^^^^^^^
我的建立脚本如下:
<javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter" destdir="bin" debug="true" deprecation="on" encoding="iso-8859-1" source="1.6" target="1.6" debuglevel="lines,source" failonerror="false" errorProperty="buildFailed"> <compilerarg line="-warn:+raw" /> <compilerarg line="-warn:-serial" /> <compilerarg line="-log source/testapp/compileLog.xml" /> <src path="testapp" /> <classpath refid="application.classpath" /> </javac>
我的一个有问题的课程中有以下代码:
public class TestEncoding { public static final String filterAccent(String s) { StringBuffer sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s.charAt(i); switch (c) { case 'á': sb.append("a"); break; case 'à': sb.append("a"); break; case 'ã': sb.append("a"); break; case 'À': sb.append("A"); break; case 'â': sb.append("a"); break; case 'Â': sb.append("A"); break; case 'ä': sb.append("a"); break; case 'Ä': sb.append("A"); break; case 'å': sb.append("a"); break; case 'Å': sb.append("A"); break; case 'ç': sb.append("c"); break; case 'Ç': sb.append("C"); break; case 'é': sb.append("e"); break; case 'É': sb.append("E"); break; case 'è': sb.append("e"); break; case 'È': sb.append("E"); break; case 'ê': sb.append("e"); break; case 'Ê': sb.append("E"); break; case 'ë': sb.append("e"); break; case 'Ë': sb.append("E"); break; case 'í': sb.append("i"); break; case 'ì': sb.append("i"); break; case 'ï': sb.append("i"); break; case 'î': sb.append("i"); break; case 'Ï': sb.append("I"); break; default: sb.append(c); break; } } return sb.toString(); } }
我也尝试将字符集更改为UTF-16,但这次它引发了不同的错误:
build.xml:152: com.ibm.team.repository.common.validation.PropertyConstraintException: Validation errors for item: type = CompilePackage, itemId = [UUID _ORXiULV3Eea3M7KtSY0KHw] Value of attribute "compileSources.errors.sourceText" is 67854 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 58296 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 36105 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 127899 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 155844 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 120795 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 81561 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 33264 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 35163 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 96396 bytes, which is greater than the allowed encoded length of 32768 bytes. at com.ibm.team.repository.service.internal.RdbRepositoryDataMediator.failIfNecessary(RdbRepositoryDataMediator.java:456) at com.ibm.team.repository.service.internal.RdbRepositoryDataMediator.validateItem(RdbRepositoryDataMediator.java:405)
有人可以帮忙吗?
感谢致敬,
维杰雷迪。
Bit new to character set encoding formats. I have a ant build script, that compiles my java code in ISO-8859-1 format. It was working fine.
After reading couple of articles: How do I convert between ISO-8859-1 and UTF-8 in Java?
I have changed the characterSet format to UTF-8, since then the compilation issues started.
Error thrown is:
[javac] TestEncoding.java (at line 11) [javac] case '?' : [javac] ^^^^^^^^
My Build script has follows:
<javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter" destdir="bin" debug="true" deprecation="on" encoding="iso-8859-1" source="1.6" target="1.6" debuglevel="lines,source" failonerror="false" errorProperty="buildFailed"> <compilerarg line="-warn:+raw" /> <compilerarg line="-warn:-serial" /> <compilerarg line="-log source/testapp/compileLog.xml" /> <src path="testapp" /> <classpath refid="application.classpath" /> </javac>
One of my class that is having problems has following code in it:
public class TestEncoding { public static final String filterAccent(String s) { StringBuffer sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s.charAt(i); switch (c) { case 'á': sb.append("a"); break; case 'à': sb.append("a"); break; case 'ã': sb.append("a"); break; case 'À': sb.append("A"); break; case 'â': sb.append("a"); break; case 'Â': sb.append("A"); break; case 'ä': sb.append("a"); break; case 'Ä': sb.append("A"); break; case 'å': sb.append("a"); break; case 'Å': sb.append("A"); break; case 'ç': sb.append("c"); break; case 'Ç': sb.append("C"); break; case 'é': sb.append("e"); break; case 'É': sb.append("E"); break; case 'è': sb.append("e"); break; case 'È': sb.append("E"); break; case 'ê': sb.append("e"); break; case 'Ê': sb.append("E"); break; case 'ë': sb.append("e"); break; case 'Ë': sb.append("E"); break; case 'í': sb.append("i"); break; case 'ì': sb.append("i"); break; case 'ï': sb.append("i"); break; case 'î': sb.append("i"); break; case 'Ï': sb.append("I"); break; default: sb.append(c); break; } } return sb.toString(); } }
I have also tried to change the characterset to UTF-16, but this time it has thrown different errors:
build.xml:152: com.ibm.team.repository.common.validation.PropertyConstraintException: Validation errors for item: type = CompilePackage, itemId = [UUID _ORXiULV3Eea3M7KtSY0KHw] Value of attribute "compileSources.errors.sourceText" is 67854 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 58296 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 36105 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 127899 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 155844 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 120795 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 81561 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 33264 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 35163 bytes, which is greater than the allowed encoded length of 32768 bytes. Value of attribute "compileSources.errors.sourceText" is 96396 bytes, which is greater than the allowed encoded length of 32768 bytes. at com.ibm.team.repository.service.internal.RdbRepositoryDataMediator.failIfNecessary(RdbRepositoryDataMediator.java:456) at com.ibm.team.repository.service.internal.RdbRepositoryDataMediator.validateItem(RdbRepositoryDataMediator.java:405)
Can someone help on this?
Thanks and Regards,
Vijay Reddy.
原文:https://stackoverflow.com/questions/40848154
最满意答案
我同意谢尔盖的评论,但你可以这样做:
var content = new List<List<string>> { new List<string>{ "book", "code", "columnToSum" }, new List<string>{ "abc", "1", "10" }, new List<string>{ "abc", "1", "5" }, new List<string>{ "cde", "1", "6" }, }; var headers = content.First(); var result = content.Skip(1) .GroupBy(s => new { Code = s[headers.IndexOf("code")], Book = s[headers.IndexOf("book")]}) .Select(g => new { Book = g.Key.Book, Code = g.Key.Code, Total = g.Select(s => int.Parse(s[headers.IndexOf("columnToSum")])).Sum() });
哪个回报:
{ Book = abc, Code = 1, Total = 15 } { Book = cde, Code = 1, Total = 6 }
I agree with Sergey's comment but You could do something like this:
var content = new List<List<string>> { new List<string>{ "book", "code", "columnToSum" }, new List<string>{ "abc", "1", "10" }, new List<string>{ "abc", "1", "5" }, new List<string>{ "cde", "1", "6" }, }; var headers = content.First(); var result = content.Skip(1) .GroupBy(s => new { Code = s[headers.IndexOf("code")], Book = s[headers.IndexOf("book")]}) .Select(g => new { Book = g.Key.Book, Code = g.Key.Code, Total = g.Select(s => int.Parse(s[headers.IndexOf("columnToSum")])).Sum() });
Which returns:
{ Book = abc, Code = 1, Total = 15 } { Book = cde, Code = 1, Total = 6 }
相关问答
更多-
我同意谢尔盖的评论,但你可以这样做: var content = new List
- >
{
new List
{ "book", "code", "columnToSum" }, new List { "abc", "1", "10" }, new List { "abc", "1", "5" }, new List ... -
我不明白第一个“示例数据的结果”来自哪里,但控制台应用程序中的问题是您正在使用SelectMany来查看每个组中的每个项目 。 我想你只是想要: List
result = Lines .GroupBy(l => l.ProductCode) .Select(cl => new ResultLine { ProductName = cl.First().Name, Quantity ... -
这对我有用(在LINQPad中): void Main() { var data = new List
{ new Info(){ Book=1, Chapter=1, Paragraph=1, TimesRead=3}, new Info(){ Book=1, Chapter=1, Paragraph=2, TimesRead=3}, new Info(){ Book=1, Chapter=1, Paragraph=3, Time ... -
LINQ GroupBy-Rank-Sum(LINQ GroupBy-Rank-Sum)[2024-01-05]
如果我正确地阅读了这个问题,你可能会找到这样的东西: var los = new List(); string sumField = "Value1"; var result = los .Where(lo => lo.string2 == "June") .GroupBy(lo => lo.string1) .Select(g => new { Key = g.Key, Total = g .Wher ... -
Linq groupby和sum(Linq groupby and sum)[2023-05-18]
您可以删除中间选择,只需按总和对组进行排序,然后选择产品。 var list = List.GroupBy(t => t.ParentProduct) .OrderBy(group => group.Sum(t => t.NumberOfOrders)) .Select(group => group.Key); You could remove the middle select and just order the groups by the ... -
GroupBy和Sum(GroupBy and Sum)[2022-04-28]
你想要的东西像: var counts = contacts .Where(c => c.State != string.Empty) .GroupBy(i => i.Address.State, StringComparer.OrdinalIgnoreCase) .Select(grp => new { State = grp.Key, Count = grp.Count()); GroupBy返回IEnumerable> 。 由 ... -
它不是很清楚你想要什么 - 这样的事情? var Rows = allData.SelectMany(u => u._rows.Select(t => new { OA = t[4], CD = t[5], PD = t[0], DS = Convert.ToInt32(t[9]), CS = Convert.ToInt32(t[10]) })) // group by the combination of CD, OA, and PD .GroupBy(x => new { x.CD, ...
-
LINQ groupby到List
- >(LINQ groupby to List
- >)
我想你看这个: var data = Model.Where(x => x.Start.Date == DateTime.UtcNow.Date) .GroupBy(x => new { x.Start, x.Field2 }) .Select(g=>g.ToList()).ToList(); 添加一个Select呼叫以获得每个组的列表 I think you are looking this: var data = Model.Where( ... -
在GroupBy和Sum聚合上使用LINQ on observable(Using LINQ on ObservableCollection with GroupBy and Sum aggregate)[2022-07-19]
.GroupBy(category => category.ItemCategory); 返回一个可枚举的IGrouping对象,其中每个IGrouping的键是一个不同的ItemCategory值,该值是MoneySpent对象的列表。 因此,您无法像现在这样将这些分组简单地放入ObservableCollection中。 相反,您可能希望将每个分组结果选择为新的MoneySpent对象: var finalQuery = boughtItemsToday .GroupBy(category => ... -
这应该做你想做的事情: var orders = br.CustOrderList .GroupBy(x => x.ZipCode) .Select(g => new { ZipCode = g.Key, Orders = g.SelectMany(x => x.OrderList) }); This should do what you want: var orders = br.CustOrderList .GroupBy(x = ...