【问题标题】:groovy, encodeBase64 is adding a character to the stringgroovy,encodeBase64 正在向字符串中添加一个字符
【发布时间】:2019-08-05 19:57:08
【问题描述】:

这是我期待的输出:

echo test | base64
dGVzdAo=
echo dGVzdAo= | base64 --decode
test

但这就是 groovy 给我的:

def test = 'test'
print test.bytes.encodeBase64()
dGVzdA==

当我解码时,我看到:

echo dGVzdA== | base64 --decode
test%

如何防止 groovy 中的 encodeBase64() 这样做?

【问题讨论】:

    标签: groovy


    【解决方案1】:

    这不一样。 echo 在末尾添加换行符。做同样的事情,会得到同样的结果。

     % echo -n test | base64
    dGVzdA==
    
    groovy:000> "test\n".bytes.encodeBase64()
    ===> dGVzdAo=
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-27
      • 2011-04-22
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2021-01-28
      • 1970-01-01
      相关资源
      最近更新 更多