首页 \ 问答 \ apache poi从右到左(right to left with apache poi)

apache poi从右到左(right to left with apache poi)

我正在使用apache poi来修改一些现有的rtf文件,并在Web应用程序中将副本返回给客户端。当我尝试替换一些文本并插入另一个用阿拉伯语代替时,发送给我。 我的代码:

    FileInputStream in = new FileInputStream(mypath);
            POIFSFileSystem fs = new POIFSFileSystem(in);

            HWPFDocument doc = new HWPFDocument(fs);



            Range r = doc.getRange();
             r.replaceText("<matricule>","  "+agent.getMatriculeAgent());
            r.replaceText("<cin>","  "+agent.getCin());
             OutputStream out = response.getOutputStream();
        response.setContentType("application/rtf");

        response.setHeader("Content-Disposition","attachment; filename="+fileName);
        doc.write(out);
        out.flush();

如何设置rtf对齐?


i'm using apache poi to modify some existing rtf files and return a copy to the client in a web application the issu with me is when i try to replacesome text and insert another wich is in arabic instead. here my code :

    FileInputStream in = new FileInputStream(mypath);
            POIFSFileSystem fs = new POIFSFileSystem(in);

            HWPFDocument doc = new HWPFDocument(fs);



            Range r = doc.getRange();
             r.replaceText("<matricule>","  "+agent.getMatriculeAgent());
            r.replaceText("<cin>","  "+agent.getCin());
             OutputStream out = response.getOutputStream();
        response.setContentType("application/rtf");

        response.setHeader("Content-Disposition","attachment; filename="+fileName);
        doc.write(out);
        out.flush();

how to set an rtf alignement ?


原文:https://stackoverflow.com/questions/13477271
更新时间:2022-04-05 10:04

最满意答案

在C ++标准中,定义了一个种族:

1.10 / 4:如果其中一个表达式评估修改了内存位置,而另一个表达式评估访问或修改了相同的内存位置,则冲突。

1.10 / 21:如果一个程序的执行包含一个数据竞争,如果它包含两个不同线程中的冲突动作,其中至少有一个不是原子的,而且两个都不会发生在另一个线程之前。 任何这样的数据竞争都会导致未定义的行为。

假设你有多个线程运行相同的代码,由于func()总是返回0(你的声明),所有线程都不能改变x的内容。 而且,y是由线程执行的函数的局部变量,所以它不被共享。 因此,在这种情况下不会出现竞争状况。

编译器不允许进行与第二个片段相对应的转换,因为:

1.10 / 22:编译器转换将分配引入可能共享的内存位置,这个内存位置不会被抽象机器修改,这个标准通常会被排除在外,因为这样的分配可能会在另一个抽象机器执行不会遇到数据竞争。

但是如果你自己写了这段代码,在上面解释的条件下可能遇到赛车条件,因为x不是原子的,并且在一个线程( temp=x )中可以有读取访问权限,在另一个线程中可以写入访问权限( x=0或in另一个线程的默认部分( x=temp


In the C++ standard, a race is defined:

1.10/4: Two expression evaluations conflict if one of them modifies a memory location and the other one accesses or modifies the same memory location.

1.10/21: The execution of a program contains a data race if it contains two conflicting actions in different threads, at least one of which is not atomic, and neither happens before the other. Any such data race results in undefined behavior.

Supposing that you have several threads running the same code, due to the fact that func() would always return 0 (your claim), none of the threads could change the content of x. Furthermore, y is a local variable of a function executed by a thread, so it is not shared. Hence, no race condition could occur in this scenario.

The compiler is not allowed to make the transformations corresponding to the second snippet because:

1.10/22: Compiler transformations that introduce assignments to a potentially shared memory location that would not be modified by the abstract machine are generally precluded by this standard, since such an assignment might overwrite another assignment by a different thread in cases in which an abstract machine execution would not have encountered a data race.

But if yourself write the snippet, under the conditions explained above might encounter racing conditions since the x is not atomic, and there could be read access in one thread (temp=x) and write access in the other (either x=0 or in the default section of the other thread (x=temp)

相关问答

更多
  • 您可以尝试将过程定义为: def process(sessions, user): ... 把它放在你喜欢的任何地方。 然后,当您调用p.map您可以使用functools.partial函数,该函数允许以增量方式指定参数: from functools import partial ... p.map(partial(process, sessions), sessions_id) 这不应该减慢处理速度并回答您的问题。 请注意,您可以使用以下方法执行相同操作: p.map(lambda ...
  • 我知道这是怎么回事,可能有几种情况。 它可能是一个开发服务器,数据是假的。 它可能会被抛弃 他们必须运行一些维护,在此期间一些懒惰的开发人员,打开端口和安全性。 大多数生产数据库都足够密封,因为你称它为“大”公司,很可能他们必须完成它。 什么可能是这样的情况取决于你甚至可以通过刑事通知公司,而不是每个公司都以适当的方式对第三方进行错误审查。 如果他们有适当的bug赏金计划,虽然他们可能会给你奖励。 谨慎行事。 I see where this is going, there may be several c ...
  • foo()很短,每个线程可能在下一个线程之前完成。 如果在u++之前的foo()添加一个随机时间的睡眠,你可能会看到你期望的内容。 foo() is so short that each thread probably finishes before the next one even gets spawned. If you add a sleep for a random time in foo() before the u++, you may start seeing what you expect ...
  • 在C ++标准中,定义了一个种族: 1.10 / 4:如果其中一个表达式评估修改了内存位置,而另一个表达式评估访问或修改了相同的内存位置,则冲突。 1.10 / 21:如果一个程序的执行包含一个数据竞争,如果它包含两个不同线程中的冲突动作,其中至少有一个不是原子的,而且两个都不会发生在另一个线程之前。 任何这样的数据竞争都会导致未定义的行为。 假设你有多个线程运行相同的代码,由于func()总是返回0(你的声明),所有线程都不能改变x的内容。 而且,y是由线程执行的函数的局部变量,所以它不被共享。 因此,在 ...
  • 有可能,您必须使用标志PTHREAD_PROCESS_SHARED: pthread_mutexattr_t mattr; pthread_mutexattr_init(&mattr); pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); // Init the shared mem barrier if ( (rv = pthread_mutex_init(&nshared, &mattr)) != 0 ) { fpr ...
  • 是的,存在竞争条件,因为在大多数处理器上double变量不是原子的。 使用3个双打(可能是一个数组,其间填充了额外的填充,以避免错误共享导致性能下降)。 一个由读者拥有,一个由作者拥有,一个由交付。 要写入:写入写入插槽,然后用写入插槽的指针/索引与切换插槽的索引原子交换(例如,使用InterlockedExchange )。 由于索引是指针大小或更小,只要变量正确对齐,原子交换就很容易。 如果碰巧你的平台提供了带有和没有记忆障碍的互锁交换,那么使用它。 读取:将读取插槽的指针/索引与切换变量的索引进行原子 ...
  • while (coming data){ if (main_thread_work){ pthread_cond_wait(&count_cond, &cs.mutex1) } pthread_mutex_lock(&cs.mutex1); 这显然是不对的。 除非持有保护它的锁,否则无法检查main_thread_work 。 如何调用pthread_cond_wait释放它不能保存的锁?! 这应该是这样的: void* task(void* arg){ ...
  • int my_shmid = shmget(key,size,shmflgs); ... void* address_of_my_shm1 = shat(my_shmid,0,shmflags); Object* optr = static_cast(address_of_my_shm1); ...或者,在其他一些线程/进程中,您安排通过其他方式传递address_of_my_shm1 ... void* address_of_my_shm2 = shat(my_shmid,addre ...
  • data是具有自动存储持续时间的对象。 一旦超出范围,它就不再有效。 我假设,在工作线程有机会获取信息之前, data超出了范围。 要解决这个问题,基本上有两种选择: 创建一个同步对象(例如CEvent ),并在完成读取数据时让工作线程发出信号。 在主线程中调用WaitForSingleObject来阻止执行,直到发生这种情况。 这会遇到死锁,例如当工作线程死亡时。 更简单的解决方案是使用动态内存管理。 使用new分配CWorkerData实例并将地址传递给工作线程。 然后,只要完成对象,工作线程就可以调用 ...
  • 你提到的“有些人”是完全正确的。 使用volatile确保每次在代码中执行此操作时读取或写入内存位置。 它不保证该值是当前值, 也不保证可能在单独的核心或单独的CPU上运行的其他线程。 为此你需要一个记忆障碍。 当在设备驱动程序中使用时,为了读取或写入外部硬件,这不是问题,因为硬件将被映射到非高速缓存的内存。 The "some people" you refer to are entirely correct. The use of volatile does guarantee that the mem ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)