小编GLa*_*DOS的帖子

在callable.call中没有关闭的BufferedReader会发生什么?

我有三个问题.

为了解释,我正在审查某人的代码,并注意到BufferedReader有时候没有关闭.通常,Eclipse会发出警告,这是一个潜在的内存泄漏(我修复了它).但是,在Callable内部类中,没有警告.

class outerClass {
    ...
    public void someMethod() {
        Future<Integer> future = outputThreadPool.submit(new innerClass(this.myProcess.getInputStream(), threadName));
        ...
    }

    class innerClass implements Callable<Integer> {
        private final InputStream stream;
        private final String prepend;

        innerClass(InputStream stream, String prepend) {
            this.stream = stream;
            this.prepend = prepend;
        }

        @Override
        public Integer call() {
            BufferedReader stdOut = new BufferedReader(new InputStreamReader(stream));
            String output = null;
            try {
                while ((output = stdOut.readLine()) != null) {
                    log.info("[" + prepend + "] " + output);
                }

            } catch …
Run Code Online (Sandbox Code Playgroud)

java eclipse callable inner-classes bufferedreader

8
推荐指数
1
解决办法
1万
查看次数

使用 webpack ts-loader 时打字稿源不显示

我正在使用来自 grunt 任务的 webpack 和 ts-loader 来转换 Typescript 并生成用于调试生产的源映射。我的团队希望能够看到原始 Typescript 源代码,而不仅仅是 JavaScript 源代码。我仔细研究了多页文档和许多问题/答案,寻找正确的解决方案,但到目前为止我在浏览器中看不到 Typescript 文件,只能看到 JavaScript 版本。

我们的项目根模块,或 webpack 任务的“入口” webpackEntry,是一个 Javascript 文件,它需要 JavaScript 文件,其中一些是从 TypeScript 编译的,但有些只是手动创建的。

我有一个 webpack "prod" 任务配置如下:

        webpack: {
        options: {
            entry: webpackEntry,
            output: {
                path: webpackDest,
                filename: 'app-min.js',
                libraryTarget: "assign",
                pathInfo: true
            },
            externals: grunt.file.readJSON('app-ui/webpack-externals.json'),
            progress: true
        },
        prod: {
            devtool: 'source-map',
            plugins: [
                new webpack.optimize.UglifyJsPlugin(),
                new webpack.optimize.OccurenceOrderPlugin(),
                new webpack.optimize.DedupePlugin(),
                new webpack.SourceMapDevToolPlugin({
                    test:  /\.tsx?$/,
                    exclude: 'node_modules',
                    module: true,
                    filename: '[file].map',
                    append: false
                })
            ], …
Run Code Online (Sandbox Code Playgroud)

gruntjs typescript webpack ts-loader

6
推荐指数
1
解决办法
3826
查看次数

使材质 UI 抽屉保持相同的大小,而不是在内容大小更改时调整大小

我正在使用带有抽屉的 Material UI。

在抽屉里,是一组可折叠的列表。当我展开列表时,列表文本项可能很长,而抽屉跳出的范围更广。我希望抽屉的宽度是窗口大小的 30%,但是当我尝试在抽屉上设置类时,root 和模态 classNames 似乎都没有固定抽屉宽度。

这是抽屉代码:

<Drawer classes={drawerClasses} open={showStandardDrawer} anchor={"right"} onClose={closeDrawer}>

 {Array.from(items).map((item, index) => {
      return (
      <List
          key={`list-${index}`}
          component="div"
          aria-labelledby="nested-list-subheader"
          subheader={
             <ListSubheader component="div" id="nested-list-subheader">
                 {item.title}
             </ListSubheader>
          }
          className={classes.root}
      >
         { item.elements.map((el, index) => {
             return (
              <React.Fragment key={index}>
                  <ListItem key={index} button onClick={() => handleExpand(index)}>
                     <ListItemText primary={el.name} />
                          {open[index] ? <ExpandLess /> : <ExpandMore />}
                  </ListItem>
                  <Collapse in={open[index]} timeout="auto" unmountOnExit>
                      { el.descriptions.map((description, index) => {
                           return (
                               <List key={`l-${index}`} component="div" disablePadding>
                                 <ListItem button className={classes.nested} >
                                     <ListItemIcon>
                                        <StarBorder …
Run Code Online (Sandbox Code Playgroud)

css drawer reactjs material-ui

3
推荐指数
1
解决办法
3695
查看次数

是否有一种不太笨拙的方法来存储Ruby哈希值?

我在Ruby中有哈希哈希值,我正在插入新的哈希值或向现有哈希值添加值.我一直觉得Ruby有更好的方法来做到这一点:

map   # => { 1 => {:type => "humbug", :name => "grinch" }, 2 => {:type => 2 } }

  if map[key]
    map[key].store(:name, value)
  else
    map[key] = { name: value }
  end
Run Code Online (Sandbox Code Playgroud)

我希望能够做类似的事情

map[key].store(:name, value) || map[key] = {name: value}
Run Code Online (Sandbox Code Playgroud)

当然失败了,如果没有的valuemap[key] ...的建议?

ruby ruby-on-rails hashmap

2
推荐指数
1
解决办法
61
查看次数