我正在编写用于将文件从客户端上传到我的服务器的代码,性能没有我想象的那么快.
我有正在进行文件传输的当前代码片段,我想知道如何加快传输速度.
抱歉,所有代码:
InputStream fileItemInputStream ;
OutputStream saveFileStream;
int[] buffer;
while (fileItemInputStream.available() > 0) {
buffer = Util.getBytesFromStream(fileItemInputStream);
Util.writeIntArrToStream(saveFileStream, buffer);
}
saveFileStream.close();
fileItemInputStream.close();
Run Code Online (Sandbox Code Playgroud)
Util方法如下:
public static int[] getBytesFromStream(InputStream in, int size) throws IOException {
int[] b = new int[size];
int count = 0;
while (count < size) {
b[count++] = in.read();
}
return b;
}
Run Code Online (Sandbox Code Playgroud)
和:
public static void writeIntArrToStream(OutputStream out, int[] arrToWrite) throws IOException {
for (int i = 0; i < arrToWrite.length; i++) {
out.write(arrToWrite[i]);
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在玩ASP.NET MVC并且有一个问题.或者也许我担心这样做是错误的.只是在一个跛足的地方工作,伸展我的翅膀.对不起,这个问题根本不简洁.
好的,这是场景.当用户访问home/index时,该页面应显示产品列表和文章列表.文件布局是这样的(DAL是我的数据访问层):
Controllers
Home
Index
Views
Home
Index inherits from ViewPage
Product
List inherits from ViewUserControl<IEnumerable<DAL.Product>>
Single inherits from ViewUserControl<DAL.Product>
Article
List inherits from ViewUserControl<IEnumerable<DAL.Article>>
Single inherits from ViewUserControl<DAL.Article>
Controllers.HomeController.Index produces a View whose ViewData contains two entries, a IEnumerable<DAL.Product> and a IEnumerable<DAL.Article>.
View.Home.Index will use those view entries to call:
Html.RenderPartial("~/Views/Product/List.ascx", ViewData["ProductList"])
and Html.RenderPartial("~/Views/Article/List.ascx", ViewData["ArticleList"])
View.Product.List will call
foreach(Product product in View.Model)
Html.RenderPartial("Single", product);
View.Article.List does something similar to View.Product.List
Run Code Online (Sandbox Code Playgroud)
然而,这种方法失败了 这种方法对我来说很有意义,但也许对这些MVC平台有更多经验的人会认识到更好的方法.
以上内容在View.Product.List中产生错误.打电话Html.RenderPartial("Single",...)抱怨没有找到"单一"视图.错误表明:
The partial view …
可能重复:
如何从Windows命令行获取应用程序退出代码?
在Unix/bash中,我可以简单地说:
$ echo $?
从交互式和非交互式shell中找出程序的返回/退出代码.
现在,我如何在Windows/cmd.exe中执行等效操作?
是否值得尝试将GUI保持在系统外观?
每个主要程序都有自己的... ...(视觉工作室,iexplorer,firefox,赛门铁克公用事业,adobe ...)
或者只是框架和对话框应该留在系统中看起来感觉范围?
更新:
一个简单的例子,如果你想在你的标签上添加一个关闭按钮,通常你会反对你当前的桌面主题.但是,如果用户具有不同的主题,则关闭按钮不合适,它不再适合系统外观.
我玩过uxtheme api,但你没有什么可以做的,我见过的一些主题是不完整的集合.
所以为了解决这个问题,我看到的最好的方法就是像你的主题一样使用visual studio/firefox/chrome roolup你自己的标签控件...
在Eclipse RCP的做事方式中,我应该在哪里保留我的模型对象?当他们被加载或更改时,他们应该如何与观点交谈?
我试图将我现有的应用程序移植到Eclipse RCP.它可以被视为类似IDE的应用程序:我打开一个文件,其中包含源文件的链接.源文件显示在树视图中.我可以编辑源代码,并将源代码构建到某个输出中......
例如,当我处理Open命令时,我将在哪里创建模型对象,以便我的视图可以看到它们?我宁愿避免使用单例管理器类,但这可能是最简单的方法.
我发现浏览JDT源代码的有趣代码是JavaCore,JavaModel,JavaModelManager.和JavaProject.
IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
Run Code Online (Sandbox Code Playgroud)
public static IJavaProject create(IProject project) {
if (project == null) {
return null;
}
JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
return javaModel.getJavaProject(project);
}
Run Code Online (Sandbox Code Playgroud)
有关:
哪些Java库可以快速实现浮点或定点操作,精度为几千位?他们的表现如何?
对我来说,一个要求是它实现了一种乘法算法,该算法优于天真乘法算法,该算法花费4倍于2倍大数字的数字(比较乘法算法).
我将以下语句放在xaml的网格的第二行中:
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
<ListView Name="listView" Margin="5" Grid.Row="1">
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridViewColumn DisplayMemberBinding="{Binding Path=DateTime}" Header="Date Time" Width="140"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Vehicle}" Header="Vehicle" Width="130"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=AlarmType}" Header="Alarm Type" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Direction}" Header="Direction" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Speed}" Header="Speed" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Alarmed}" Header="Alarmed" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=LoadType}" Header="Load Type" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Status}" Header="Status" Width="110"/>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我将listView.ItemSource绑定到代码中定义的ObservableCollection,以将数据填充到列表中.当添加到GridView的项目数超过列表视图高度时,垂直滚动条没有像我在XAML中指定的那样出现.我做错了什么?非常感谢您的意见.谢谢.
我希望能够在Rails中比较Dates和Times,而无需始终调用to_time或to_date方法.所以我写了下面的代码:
class Date
def ==(other)
if other.kind_of?(Time)
self.to_time == other
else
super(other)
end
end
end
Run Code Online (Sandbox Code Playgroud)
我知道有一种简单的方法可以写这个,这样我就可以为>,<,> =,<=和<=>做这个工作.但我忘记了:P有什么想法吗?
我一直在阅读System库set和get方法的细节,但参数通常是字符串.
你是否会考虑使用Stringas作为参数的不良做法enum?
最好的替代方案可能是public final String,不是吗?
我讨厌不得不问,但我已经被困在这里了.
我需要测试一系列数字来找到第一个有超过500个因子的数字:http: //projecteuler.net/index.php?section = problem&id = 12
- 首先我试图强行回答(在很长一段时间后找到一个480的数字)
- 我现在正在考虑确定数字的素因子,然后用它们来找出所有其他因素.
我目前处于可以获得任何数字输入的一系列素数因子的阶段 - 即300具有素因子2 2 3 5 5
使用这个素数因子我需要能够计算剩余因子 - 这是我坚持的部分.基本上,据我所知,我需要计算数组中所有可能的数字组合......
即2*2
2*2*3
2*2*3*5
2*3
2*3*3
......等等 - 但有趣的地方是......
2*5
2*3*5
...即阵列中彼此不相邻的数字
对于任何长度数组,我都想不出以通用的方式编写代码的方法......
我需要帮助!PS - 我在Java工作
编辑:我的强力代码 - 因为它已被建议暴力强迫问题将工作,所以我的代码可能有一个错误:(
package euler.problem12;
public class Solution {
public static void main(String[] args) {
int next = 1;
int triangle = 0;
int maxFactors = 0;
while(true) {
triangle = triangle + next;
int factors = 1;
int max = (int) …Run Code Online (Sandbox Code Playgroud) java ×5
asp.net-mvc ×1
cmd ×1
const ×1
eclipse ×1
eclipse-rcp ×1
enums ×1
file-io ×1
gridview ×1
listview ×1
return-code ×1
ruby ×1
scrollviewer ×1
string ×1
usability ×1
windows ×1
wpf ×1